查看“Clock”的源代码
←
Clock
跳转至:
导航
、
搜索
因为以下原因,您没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看与复制此页面的源代码。
{| style="width: 800px;" |- | ==Objective== The course will show you how to use Processing to display a Microduino clock. ==Equipment== *'''[[Microduino-Core]]''' *'''[[Microduino-FT232R]]''' *'''[[Microduino-RTC]]''' *Other Hardware Equipment **A USB cable ==Schematic== Just stack the three Microduino modules needed together ==Program== Referring to ProcessingColock MicroduinoColock ==Debugging== Step 1:Build the hardware environment on the basis of the schematic, as follows: [[File:processingColockConnectionDiagram.jpg|600px|center|thumb]] Step 2:Here the code needed: The code of the two ends (Processing and Microduino) Microduino: //Just run the RTC module and transmit time data to the serial port void loop() { rtc.formatDate(); rtc.formatTime(); //send time data to port Serial.print(rtc.getHour()); Serial.print(":"); Serial.print(rtc.getMinute()); Serial.print(":"); Serial.println(rtc.getSecond()); } //Initialize time //inital time void vosettime() { //rtc.initClock(); //day, weekday, month, century(1=1900, 0=2000), year(0-99) rtc.setDate(4, 1, 6, 0, 14); //hr, min, sec rtc.setTime(15, 28, 50); } Processing: //Define the first serial data after getting it, and cache it if there is a new line // List all the available serial ports in the output pane. // You will need to choose the port that the Wiring board is // connected to from this list. The first port in the list is // port #0 and the third port in the list is port #2. println(Serial.list()); // Open the port that the Wiring board is connected to (in this case #0) // Make sure to open the port at the same speed Wiring is using (9600bps) port = new Serial(this, Serial.list()[0], 9600); //Initialize the center point position of the clock as well as the length of the hour hand, minute hand and the second hand int radius = min(width, height)/2; secR = radius * 0.72; minR = radius * 0.60; hourR = radius * 0.50; clockDiameter = radius * 1.8; cx = width /2 ; cy = height /2 ; //Draw the current value after getting the x-coordinate value of the mouse via serial output void update(int x) { port.write(x); stroke(255); line(mouseX, 0, mouseX, 160); text (mouseX, mouseX, 180); } //Receive the serial data and process time information //split data by ":" String time[]=val.split(":"); //if some exception happend, initial time is 0 colock try { hour=Integer.parseInt(time[0]); minute=Integer.parseInt(time[1]); second=Integer.parseInt(time[2]); } catch (NumberFormatException e) { hour=0; minute=0; second=0; } //Draw a clock float s = map(second, 0, 60, 0, TWO_PI) - HALF_PI; float m = map(minute+norm(second, 0, 60), 0, 60, 0, TWO_PI)- HALF_PI; float h = map(hour+norm(minute, 0, 60), 0, 24, 0, TWO_PI * 2 ) - HALF_PI; //draw clock stroke(255, 250, 0); strokeWeight(1); line(cx, cy, cx + cos(s) * secR, cy + sin(s) * secR); strokeWeight(2); line(cx, cy, cx+ minR * cos(m), cy + minR * sin(m)); strokeWeight(4); line(cx, cy, cx + hourR * cos(h), cy + hourR * sin(h)); strokeWeight(2); stroke(255, 0, 0); for (int a = 0 ;a<360;a+=6) { float angle = radians(a); float cx1 = (secR+20) * cos(angle); float cy1 = (secR+20) * sin(angle); point(cx + cx1, cy + cy1); if (a%30==0) { line(cx+cx1, cy+cy1, cx+cx1*0.98, cy+cy1*0.98); fill(255); int mark; if (a/30>9) { mark = a/30 -9; } else { mark = a/30 +3; } text(mark, cx+cx1*1.05-5, cy+cy1*1.05+5); } fill(90, 155, 11); text(hour+":"+minute+":"+second, cx-25, cy+100); text("Microduino", cx-25, cy-100); } Step 3:Download the code and get it complied successfully. Step 4:Focus on Processing after the system goes well. ==Result== A running clock will be displayed on the screen, just like this [[File:processingColockResult.jpg|600px|center|thumb]] ==Video== |}
返回至
Clock
。
导航菜单
个人工具
创建账户
登录
名字空间
页面
讨论
变种
视图
阅读
查看源代码
查看历史
更多
搜索
Welcome
首页
创客大赛
大赛详情
3D打印
安装月球车
图形化编程
操控月球车
升级月球车
编程工具下载
软件下载
Arduino
Processing
Mixly
Scratch
模块套件
Microduino 102
mCookie 102
mCookie 202
mCookie 302
IBC
其他
应用套件
四轴飞行器
平衡车
小车CUBE
音乐播放器
刷卡音乐播放器
wifi气象站
彩虹音乐触摸灯
分贝检测仪
迎门汇报
LED点阵时钟
LED点阵屏幕
硬件
mCookie
Sensor
Microduino
MicroWrt
MicroNux
MicroRobot-Core
MicroRobot-CoreESP
ideaBoard
ideaBox
MicroMV
MicroAI
帮助
常见问题
帮助
工具
链入页面
相关更改
特殊页面
页面信息