极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 15892|回复: 8

RGBCLOCK第二版---小太鼓面世啦

[复制链接]
发表于 2016-3-20 11:05:06 | 显示全部楼层 |阅读模式
本帖最后由 Cambridge 于 2016-3-27 11:05 编辑


有没有觉得很萌呢!

之前做的RGBclock感觉有点简陋哈哈,连完线写个程序跑了下之后就放一边了,这样有点浪费唉,于是就开始做模型打印出来,加上电路组装成一个完整的小太鼓时钟。
而且比第一版多了设置闹钟的功能,并且用processing做了个上位机来设置闹钟。闹钟可以根据星期几来设置,而且利用TF卡模块和SimpleSdAudio库来储存和播放音乐,效果十分好啊。


那么怎么看时间呢?!红色代表的是时针,这个很简单,变色的代表了秒针,有点酷炫哈哈,然后分钟也会慢慢变色,从绿色渐变到橙色,代表了新的一个5分钟到9分钟,例如15分是绿色,19分就是橙色了。
大家可以下载和修改程序,例如把上位机的界面修改了,更改自己喜欢的音乐做铃声,等等。

注意!先要在EEPROM的地址1,2分别写入当前的星期和日才能正常运行!
关于铃声,请看链接  http://www.arduino.cn/thread-2944-1-1.html


接线如下:


arduino代码:
  1. #include <EEPROM.h>
  2. #include <Adafruit_NeoPixel.h>
  3. #include <Wire.h>
  4. #include "RTClib.h"
  5. #include <SimpleSDAudio.h>

  6. #ifdef __AVR__
  7.   #include <avr/power.h>
  8. #endif

  9. #define PIN 6

  10. #define BIGBUFSIZE (2*512)      // bigger than 2*512 is often only possible on Arduino megas!
  11. uint8_t bigbuf[BIGBUFSIZE];

  12. RTC_DS1307 rtc;

  13. //初始化ws2812
  14. Adafruit_NeoPixel strip = Adafruit_NeoPixel(12, PIN, NEO_GRB + NEO_KHZ800);

  15. String data1 = "";

  16. String  musicName[6] ;

  17. char charactor;
  18. //记得改音乐的名字,TF卡里面的也要改,短一点比较好。
  19. char  musicName0[16] = "XIAO.AFM";  
  20. char  musicName1[16] = "FEEL.AFM";
  21. char  musicName2[16] = "YOUNG.AFM";
  22. char  musicName3[16] = "WHAT.AFM";
  23. char  musicName4[16] = "ME.AFM";
  24. char  musicName5[16] = "RESET.AFM";

  25. int h = 0,m = 0,s = 0,d = 0;
  26. int lastsecond = 0,lastminute = 0,lasthour = 0,scale = 0;
  27. int alarmH1 = 0,alarmM1 = 0;
  28. int alarmH2 = 0,alarmM2 = 0;
  29. int alarmh1 = 0,alarmm1 = 0;
  30. int alarmh2 = 0,alarmm2 = 0;
  31. int music = 0,week = 0,WEEKDAY = 0,MUSIC = 0,LASTDAY = 0;

  32. void setup(){
  33.   pinMode(13,OUTPUT);

  34.   #if defined (__AVR_ATtiny85__)
  35.   if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
  36.   #endif
  37.   strip.begin();
  38.   strip.show(); // Initialize all pixels to 'off'
  39.   Serial.begin(57600);

  40. #ifdef AVR
  41.   Wire.begin();
  42. #else
  43.   Wire1.begin(); // Shield I2C pins connect to alt I2C bus on Arduino Due
  44. #endif

  45.   rtc.begin();
  46.   if (! rtc.isrunning()) {
  47.     rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  48.   }
  49.   digitalWrite(13,LOW);
  50.   
  51.   SdPlay.setWorkBuffer(bigbuf, BIGBUFSIZE);
  52.   SdPlay.init(SSDA_MODE_FULLRATE | SSDA_MODE_MONO | SSDA_MODE_AUTOWORKER);

  53. //EEPROM里面储存了星期几和对应的闹钟
  54.   WEEKDAY = EEPROM.read(1);
  55.   LASTDAY = EEPROM.read(2);
  56.   MUSIC = EEPROM.read(3);
  57.   alarmH1 = EEPROM.read((WEEKDAY-1) * 4 + 4);
  58.   alarmM1 = EEPROM.read((WEEKDAY-1) * 4 + 5);
  59.   alarmH2 = EEPROM.read((WEEKDAY-1) * 4 + 6);
  60.   alarmM2 = EEPROM.read((WEEKDAY-1) * 4 + 7);
  61.   
  62.   //下面这段主要是消除杂音
  63.   SdPlay.setFile(musicName0);
  64.   delay(1000);
  65.   SdPlay.play();
  66.   delay(500);
  67.   SdPlay.stop();
  68. }
  69. void loop(){

  70.   DateTime now = rtc.now();
  71.   h = now.hour();
  72.   m = now.minute();
  73.   s = now.second();
  74.   d = now.day();
  75.   
  76.   if(LASTDAY !=d){
  77.     LASTDAY = d;
  78.     WEEKDAY++;
  79.     if(WEEKDAY > 7){
  80.       WEEKDAY = 1;
  81.     }
  82.     EEPROM.write(2,d);
  83.     EEPROM.write(1,WEEKDAY);
  84.     alarmH1 = EEPROM.read((WEEKDAY-1) * 4 + 4);
  85.     alarmM1 = EEPROM.read((WEEKDAY-1) * 4 + 5);
  86.     alarmH2 = EEPROM.read((WEEKDAY-1) * 4 + 6);
  87.     alarmM2 = EEPROM.read((WEEKDAY-1) * 4 + 7);
  88.   }
  89.   //判断闹钟
  90.   Alarm(alarmH1,alarmM1);
  91.   Alarm(alarmH2,alarmM2);
  92.   
  93.   if(h>=12)h=h-12;
  94.   strip.setBrightness(64);
  95.   if(h!=m/5){
  96.    
  97.   //以下是时钟的显示
  98. /*hour*/
  99.     if(h!=lasthour){
  100.       strip.setPixelColor(lasthour, strip.Color(0,0,0));
  101.       lasthour=h;
  102.       //if(lasthour==0)lasthour=12;         
  103.     }
  104.    
  105.     strip.setPixelColor(h, strip.Color(150,0,4*m));
  106.     strip.show();
  107.     delay(20);
  108.   
  109. /*minute*/
  110.     if(m/5!=lastminute){
  111.       strip.setPixelColor(lastminute, strip.Color(0,0,0));
  112.       lastminute=m/5;
  113.       //if(lastminute==0)lastminute=12;   
  114.     }
  115.     scale=m/5;
  116.     scale=50*(m-scale*5);
  117.     strip.setPixelColor(m/5, strip.Color(s+scale,150,0));
  118.     strip.show();
  119.     delay(20);
  120.   }
  121.   
  122. /*second*/
  123.   uint16_t j;
  124.   for(j=0; j<256; j++) {
  125.     //eeprom_write();
  126.     getdata();
  127.     DateTime now = rtc.now();
  128.     s=now.second();
  129.     if(s/5!=lastsecond){
  130.       strip.setPixelColor(lastsecond, strip.Color(0,0,0));
  131.       lastsecond=s/5;
  132.       //if(lastsecond==0 )lastsecond=12;        
  133.       strip.show();
  134.       if(lastsecond-1==h || lastminute-1==h)hour1(h);//in case hour pixel or minute pixel misses
  135.       if(lastsecond-1==m/5)minute1(m/5);   
  136.     }
  137.     if(h==m/5){
  138.       if(m/5!=lastminute){
  139.         strip.setPixelColor(lastminute, strip.Color(0,0,0));
  140.         lastminute=m/5;
  141.         //if(lastminute==0)lastminute=12;           
  142.       }
  143.       strip.setPixelColor(h, Wheel(((h * 256 / strip.numPixels()) + j) & 255));
  144.     }
  145.     strip.setPixelColor(s/5, Wheel(((s/5 * 256 / strip.numPixels()) + j) & 255));
  146.     strip.show();
  147.     delay(20);
  148.   }
  149.   
  150.   
  151. /*print imformation*/
  152.   //Serial.println(h);
  153. // Serial.println(m);
  154. // Serial.println(s);
  155.   Serial.println(alarmH1);
  156.   Serial.println(alarmM1);
  157.   Serial.println(alarmH2);
  158.   Serial.println(alarmM2);
  159.   Serial.println(WEEKDAY);
  160.   Serial.println(MUSIC);
  161.   //Serial.println(data);
  162. //strip.clear();
  163. //delay(5000);
  164. }

  165. void hour1(uint8_t hh) {
  166.   strip.setPixelColor(hh, strip.Color(150,0,4*m));
  167.   strip.show();
  168.   delay(20);
  169. }

  170. void minute1(uint8_t mm) {
  171.   strip.setPixelColor(mm, strip.Color(scale+s,150,0));
  172.   strip.show();
  173.   delay(20);
  174. }

  175. uint32_t Wheel(byte WheelPos) {
  176.   WheelPos = 255 - WheelPos;
  177.   if(WheelPos < 85) {
  178.     return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  179.   }
  180.   if(WheelPos < 170) {
  181.     WheelPos -= 85;
  182.     return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  183.   }
  184.   WheelPos -= 170;
  185.   return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  186. }

  187. //从上位机获取数据
  188. void getdata(){
  189.   if(Serial.available()){
  190.     //clear values   
  191.     data1 = "";
  192.     while(Serial.available()){
  193.       charactor = (char) Serial.read();
  194.       data1 += charactor;
  195.     }
  196.     week = getWeek(data1);
  197.     music = getMusic(data1);
  198.     alarmh1 = getHour1(data1);
  199.     alarmm1 = getMinute1(data1);
  200.     alarmh2 = getHour2(data1);
  201.     alarmm2 = getMinute2(data1);  
  202.     EEPROM.write((week - 1) * 4 + 4,alarmh1);
  203.     EEPROM.write((week - 1) * 4 + 5,alarmm1);  
  204.     EEPROM.write((week - 1) * 4 + 6,alarmh2);         
  205.     EEPROM.write((week - 1) * 4 + 7,alarmm2);   
  206.     EEPROM.write(3,music);   
  207.    
  208.   }
  209. }

  210. /*alarm function*/
  211. void Alarm(int ah,int am){
  212.   if(ah == h && am == m && (ah + am) != 0){
  213.     switch(MUSIC){
  214.     case 1:SdPlay.setFile(musicName1);break;
  215.     case 2:SdPlay.setFile(musicName2);break;
  216.     case 3:SdPlay.setFile(musicName3);break;
  217.     case 4:SdPlay.setFile(musicName4);break;
  218.     case 5:SdPlay.setFile(musicName5);break;
  219.   }
  220.     SdPlay.worker();
  221.     SdPlay.play();
  222.     uint16_t i, j;
  223.     while(ah == h && am == m){
  224.        DateTime now = rtc.now();
  225.        m=now.minute();     
  226.        for(j=0; j<256; j++) {
  227.          for(i=0; i<strip.numPixels(); i++) {
  228.            strip.setPixelColor(i, Wheel((i+j) & 255));
  229.          }
  230.        strip.show();
  231.        delay(20);
  232.        }
  233.     }
  234.     for(i=0; i<strip.numPixels(); i++) {
  235.       strip.setPixelColor(i,strip.Color(0,0,0));
  236.     }
  237.    
  238.   }
  239.   SdPlay.stop();
  240. }

  241. int getHour1(String p){
  242.   int h = 0,mark = 0,value = 0;
  243.   while(p[h] != 'h'){
  244.     h++;
  245.   }
  246.   while(p[mark] != 'm'){
  247.     mark++;
  248.   }
  249.   for(int i = h+1;i < mark;i++){
  250.     value = 10 * value + (int)p[i] - '0';
  251.   }
  252.   return value;
  253. }

  254. int getMinute1(String p){
  255.   int m = 0,mark = 0,value = 0;
  256.   while(p[m] != 'm'){
  257.     m++;
  258.   }
  259.   while(p[mark] != 'H'){
  260.     mark++;
  261.   }
  262.   for(int i = m+1;i < mark;i++){
  263.     value = 10 * value + (int)p[i] - '0';
  264.   }
  265.   return value;
  266. }

  267. int getHour2(String p){
  268.   int H = 0,mark = 0,value = 0;
  269.   while(p[H] != 'H'){
  270.     H++;
  271.   }
  272.   while(p[mark] != 'M'){
  273.     mark++;
  274.   }
  275.   for(int i = H + 1;i < mark;i++){
  276.     value = 10 * value + (int)p[i] - '0';
  277.   }
  278.   return value;
  279. }

  280. int getMinute2(String p){
  281.   int m = 0,mark = 0,value = 0;
  282.   while(p[m] != 'M'){
  283.     m++;
  284.   }
  285.   while(p[mark] != 'w'){
  286.     mark++;
  287.   }
  288.   for(int i = m+1;i < mark;i++){
  289.     value = 10 * value + (int)p[i] - '0';
  290.   }
  291.   return value;
  292. }

  293. int getMusic(String p){
  294.   int s = 0,value = 0;
  295.   while(p[s] != 's'){
  296.     s++;
  297.   }
  298.   value = (int)p[s+1] - '0';
  299.   return value;
  300. }

  301. int getWeek(String p){
  302.   int w = 0,value = 0;
  303.   while(p[w] != 'w' ){
  304.     w++;
  305.   }
  306.   value = (int)p[w+1] - '0';
  307.   return value;
  308. }
复制代码


processing 代码:
  1. PImage img;

  2. import processing.serial.*;

  3. Serial port;

  4. boolean alarm1hbox = false;
  5. boolean alarm1mbox = false;
  6. boolean alarm1sbox = false;

  7. boolean alarm2hbox = false;
  8. boolean alarm2mbox = false;

  9. boolean overboxconnect = false;
  10. boolean overboxweek = false;

  11. boolean click0 = false;//click for connect
  12. boolean click1 = false;//click for setting week

  13. boolean clickmusic = false;//click for setting music

  14. boolean alarm1click1 = false;//click for setting hour1
  15. boolean alarm1click2 = false;//click for setting minute1
  16. boolean alarm1click3 = false;//click for getting data and sending data

  17. boolean alarm2click1 = false;//click for setting hour2
  18. boolean alarm2click2 = false;//click for setting minute2

  19. String data1 = "";

  20. String arduinoPort;

  21. String [] weekday = new String[8];
  22. String [] musicName = new String[6];//change the music name in setup()

  23. int h1 = 0 ,m1 = 0;
  24. int h2 = 0 ,m2 = 0;
  25. int week = 1;
  26. int music = 0;

  27. void setup(){
  28.   size(768,576);
  29.   smooth();
  30.   
  31.   //change the name into yours
  32.   img = loadImage("cat2.jpg");
  33.   Serial.list();
  34.   
  35.   weekday[1] = "Monday";
  36.   weekday[2] = "Tuesday";
  37.   weekday[3] = "Wednesday";
  38.   weekday[4] = "Thursday";
  39.   weekday[5] = "Friday";
  40.   weekday[6] = "Saturday";
  41.   weekday[7] = "Sunday";
  42.   
  43.   //change the name into yours
  44.   musicName[0] = "";
  45.   musicName[1] = "Feel The Light";
  46.   musicName[2] = "Lana Del Rey";
  47.   musicName[3] = "what for";
  48.   musicName[4] = "Breathe Me";
  49.   musicName[5] = "Reset";
  50.   
  51. }

  52. void draw(){
  53.   background(255);
  54.   picture();
  55.   
  56.   UI();
  57.   
  58.   judge();
  59.   
  60.   Print();
  61.   
  62.   music();
  63.   
  64.   if(alarm1sbox && click0 &&  music != 0 && mousePressed ){
  65.     port.write(data1);
  66.   }  
  67.   
  68. }

  69. void picture(){
  70.   image(img,0,0,768,576);
  71. }

  72. void UI(){
  73.   fill(255);
  74.   strokeWeight(5);
  75.   stroke(0);
  76.   strokeJoin(ROUND);
  77.   rect(250,10,215,40);//Setting Alarm
  78.   rect(50,230,100,40);//TIME
  79.   rect(50,380,100,40);//MUSIC
  80.   strokeWeight(3);
  81.   
  82.   if(mouseX > 250 && mouseX < 390 && mouseY >100 && mouseY <130){
  83.     stroke(104);
  84.     strokeWeight(5);
  85.     overboxconnect = true;
  86.   }else{
  87.     stroke(0);
  88.     strokeWeight(3);
  89.     overboxconnect = false;
  90.   }
  91.   rect(250,100,140,30);//connect
  92.   
  93.   if(mouseX > 250 && mouseX < 410 && mouseY >180 && mouseY <210){
  94.     stroke(104);
  95.     strokeWeight(5);
  96.     overboxweek = true;
  97.   }else{
  98.     stroke(0);
  99.     strokeWeight(3);
  100.     overboxweek = false;
  101.   }
  102.   rect(250,180,160,30);//WEEK
  103.   
  104.   if(mouseX > 250 && mouseX < 300 && mouseY > 230 && mouseY < 260){
  105.     stroke(104);
  106.     strokeWeight(5);
  107.     alarm1hbox = true;
  108.   }else{
  109.     stroke(0);
  110.     strokeWeight(3);
  111.     alarm1hbox = false;
  112.   }
  113.   rect(250,230,50,30);//hour
  114.   
  115.   if(mouseX > 360 && mouseX < 410 && mouseY > 230 && mouseY < 260){
  116.     stroke(104);
  117.     strokeWeight(5);
  118.     alarm1mbox = true;
  119.   }else{
  120.     stroke(0);
  121.     strokeWeight(3);
  122.     alarm1mbox = false;
  123.   }
  124.   rect(360,230,50,30);//minute
  125.   
  126.   fill(152);

  127.   if(mouseX > 500 && mouseX < 550 && mouseY > 230 && mouseY < 260){
  128.     stroke(104);
  129.     strokeWeight(5);
  130.     alarm1sbox = true;
  131.   }else{
  132.     stroke(0);
  133.     strokeWeight(3);
  134.     alarm1sbox = false;
  135.   }
  136.   rect(500,230,50,30);//set
  137.   
  138.   fill(255);
  139.   
  140.   if(mouseX > 250 && mouseX < 300 && mouseY > 280 && mouseY < 310){
  141.     stroke(104);
  142.     strokeWeight(5);
  143.     alarm2hbox = true;
  144.   }else{
  145.     stroke(0);
  146.     strokeWeight(3);
  147.     alarm2hbox = false;
  148.   }
  149.   rect(250,280,50,30);//hour
  150.   
  151.   if(mouseX > 360 && mouseX < 410 && mouseY > 280 && mouseY < 310){
  152.     stroke(104);
  153.     strokeWeight(5);
  154.     alarm2mbox = true;
  155.   }else{
  156.     stroke(0);
  157.     strokeWeight(3);
  158.     alarm2mbox = false;
  159.   }
  160.   rect(360,280,50,30);//minute
  161.   
  162.   fill(152);
  163. /*
  164.   if(mouseX > 500 && mouseX < 550 && mouseY > 280 && mouseY < 310){
  165.     stroke(104);
  166.     strokeWeight(5);
  167.     alarm2sbox = true;
  168.   }else{
  169.     stroke(0);
  170.     strokeWeight(3);
  171.     alarm2sbox = false;
  172.   }
  173.   rect(500,280,50,30);//set*/
  174.   
  175. }

  176. void Print(){
  177.   textSize(25);
  178.   fill(0);
  179.   text("Setting Alarm",280,40);
  180.   text("TIME",70,260);
  181.   text("MUSIC",60,410);
  182.   text("WEEK:",260,205);
  183.   text(week,350,205);
  184.   text(h1,255,255);
  185.   text(":",325,250);
  186.   text(m1,365,255);
  187.   text("set",508,252);
  188.   if(alarm1click3 && click0){
  189.     text("Set An Alarm At" + ":" + h1 + ":" + m1 +"," + weekday[week],250,460);
  190.     text(h2 + ":" + m2,450,495);
  191.     if( music == 0){
  192.       text("Error!No Music!",250,530);
  193.     }else{
  194.       text("Music:" + musicName[music],250,530);
  195.     }
  196.   }
  197.   
  198.   text(h2,255,305);
  199.   text(":",325,300);
  200.   text(m2,365,305);
  201.   
  202.   
  203.   if(click0 == true){
  204.     text("disconnect",255,122);
  205.   }else if(click0 == false){
  206.     text("connect",270,122);
  207.   }
  208.   
  209. }

  210. void judge(){
  211.   
  212.   if(overboxweek){
  213.     if(mousePressed){
  214.       week = 1;
  215.       click1 = true;
  216.       alarm1click1 = false;
  217.       alarm1click2 = false;
  218.       alarm1click3 = false;
  219.       alarm2click2 = false;
  220.       alarm2click1 = false;
  221.       clickmusic = false;
  222.     }
  223.   }
  224.   
  225.   if(alarm1hbox){
  226.     if(mousePressed){
  227.       h1 = 0;
  228.       alarm1click1 = true;
  229.       alarm1click2 = false;
  230.       alarm1click3 = false;
  231.       alarm2click2 = false;
  232.       alarm2click1 = false;
  233.       click1 = false;
  234.       clickmusic = false;
  235.     }
  236.   }

  237.   if(alarm1mbox){
  238.     if(mousePressed){
  239.       m1 = 0;
  240.       alarm1click2 = true;
  241.       alarm1click1 = false;
  242.       alarm1click3 = false;
  243.       alarm2click2 = false;
  244.       alarm2click1 = false;
  245.       click1 = false;
  246.       clickmusic = false;
  247.     }
  248.   }

  249.   if(alarm1sbox){
  250.     if(mousePressed){
  251.       alarm1click1 = false;
  252.       alarm1click2 = false;
  253.       alarm1click3 = true;
  254.       alarm2click2 = false;
  255.       alarm2click1 = false;
  256.       click1 = false;
  257.       clickmusic = false;
  258.     }
  259.   }
  260.   
  261.   if(alarm1click3 && click0){
  262.     data1 = "a" + "h" + h1 + "m" + m1 + "H" + h2 + "M" + m2 + "w" + week + "s" + music;
  263.   }else{
  264.     data1 = "";
  265.   }
  266.   
  267.   if(alarm2hbox){
  268.     if(mousePressed){
  269.       h2 = 0;
  270.       alarm2click1 = true;
  271.       alarm2click2 = false;
  272.       alarm1click3 = false;
  273.       alarm1click1 = false;
  274.       alarm1click2 = false;
  275.       click1 = false;
  276.       clickmusic = false;
  277.     }
  278.   }

  279.   if(alarm2mbox){
  280.     if(mousePressed){
  281.       m2 = 0;
  282.       alarm2click2 = true;
  283.       alarm2click1 = false;
  284.       alarm1click3 = false;
  285.       alarm1click1 = false;
  286.       alarm1click2 = false;
  287.       click1 = false;
  288.       clickmusic = false;
  289.     }
  290.   }

  291. }

  292. void music(){
  293.   
  294.   fill(255);
  295.   stroke(0);
  296.   strokeWeight(3);
  297.   
  298.   if(clickmusic == false){
  299.     rect(250,380,200,30);
  300.     fill(120);
  301.     rect(450,380,30,30);
  302.     triangle(460,390,470,390,465,400);
  303.     fill(0);
  304.     textSize(25);
  305.     text(musicName[music],260,405);
  306.   }else{
  307.    
  308.     rect(250,380,200,30);
  309.    
  310.     if(mouseX > 250 && mouseX < 450 && mouseY > 410 && mouseY < 440){
  311.       fill(0,0,255);
  312.       if(mousePressed){
  313.         music = 1;
  314.         clickmusic = false;
  315.       }
  316.     }else{
  317.       fill(255);
  318.     }
  319.     rect(250,410,200,30);
  320.    
  321.     if(mouseX > 250 && mouseX < 450 && mouseY > 440 && mouseY < 470){
  322.       fill(0,0,255);
  323.       if(mousePressed){
  324.         music = 2;
  325.         clickmusic = false;
  326.       }
  327.     }else{
  328.       fill(255);
  329.     }
  330.     rect(250,440,200,30);
  331.     if(mouseX > 250 && mouseX < 450 && mouseY > 470 && mouseY < 500){
  332.       fill(0,0,255);
  333.       if(mousePressed){
  334.         music = 3;
  335.         clickmusic = false;
  336.       }
  337.     }else{
  338.       fill(255);
  339.     }
  340.     rect(250,470,200,30);
  341.    
  342.     if(mouseX > 250 && mouseX < 450 && mouseY > 500 && mouseY < 530){
  343.       fill(0,0,255);
  344.       if(mousePressed){
  345.         music = 4;
  346.         clickmusic = false;
  347.       }
  348.     }else{
  349.       fill(255);
  350.     }
  351.     rect(250,500,200,30);
  352.     if(mouseX > 250 && mouseX < 450 && mouseY > 530 && mouseY < 560){
  353.       fill(0,0,255);
  354.       if(mousePressed){
  355.         music = 5;
  356.         clickmusic = false;
  357.       }
  358.     }else{
  359.       fill(255);
  360.     }
  361.     rect(250,530,200,30);
  362.    
  363.     fill(0);
  364.     textSize(25);
  365.     text(musicName[1],260,435);
  366.     text(musicName[2],260,465);
  367.     text(musicName[3],260,495);
  368.     text(musicName[4],260,525);
  369.     text(musicName[5],260,555);
  370.     fill(120);
  371.     rect(450,380,30,30);
  372.     triangle(460,400,470,400,465,390);
  373.   }

  374. }

  375. void mousePressed(){
  376.   
  377.   if(overboxconnect){
  378.     click0 = !click0;
  379.     if(click0 == true){
  380.       arduinoPort = Serial.list()[0];
  381.       port =new Serial(this,arduinoPort,57600);
  382.     }else{
  383.       port.stop();
  384.     }
  385.   }
  386.   
  387.   if(mouseX > 450 && mouseX < 490 && mouseY > 380 && mouseY < 410){
  388.       clickmusic = !clickmusic;
  389.       alarm2click1 = false;
  390.       alarm2click2 = false;
  391.       alarm1click3 = false;
  392.       alarm1click1 = false;
  393.       alarm1click2 = false;
  394.       click1 = false;
  395.       music = 0;
  396.     }
  397.    
  398.    
  399. }

  400. void keyPressed(){
  401. //week
  402. if(click1){
  403.     week = key - '0';
  404.   }
  405.   if(week > 7 || week < 1){
  406.     week = 1;
  407.   }
  408. //hour  
  409.   if(alarm1click1){
  410.     h1 = 10 * h1 + key - '0';
  411.   }
  412.   if(h1 >= 24 || h1 < 0){
  413.       h1 = 0;
  414.   }
  415. //minute
  416.   if(alarm1click2){
  417.     m1 = 10 * m1 + key - '0';
  418.   }
  419.   if(m1 >= 60 || m1 < 0){
  420.       m1 = 0;
  421.   }
  422. //hour  
  423.   if(alarm2click1){
  424.     h2 = 10 * h2 + key - '0';
  425.   }
  426.   if(h2 >= 24 || h2 < 0){
  427.       h2 = 0;
  428.   }
  429. //minute
  430.   if(alarm2click2){
  431.     m2 = 10 * m2 + key - '0';
  432.   }
  433.   if(m2 >= 60 || m2 < 0){
  434.       m2 = 0;
  435.   }
  436. }
复制代码


打个小广告,需要打印外壳的可以找我啦哈哈哈

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x

评分

参与人数 1 +1 收起 理由
幻生幻灭 + 1 赞一个!

查看全部评分

回复

使用道具 举报

发表于 2016-3-20 18:45:23 | 显示全部楼层
赞一个,太厉害了
回复 支持 反对

使用道具 举报

发表于 2017-7-31 16:58:24 | 显示全部楼层
楼主模型有两个是重复的少了腿
回复 支持 反对

使用道具 举报

发表于 2017-8-9 18:50:56 | 显示全部楼层
萌萌达!!
真是一个有意思的设计
回复 支持 反对

使用道具 举报

发表于 2018-1-14 13:21:09 | 显示全部楼层
请问下processing上位机怎么弄,一点概念都没得,楼主普及下
回复 支持 反对

使用道具 举报

发表于 2018-3-6 16:38:57 | 显示全部楼层
赞一个,太厉害了
回复 支持 反对

使用道具 举报

发表于 2018-3-6 17:18:59 | 显示全部楼层
赞! 不知道怎么玩儿啊?是不是要敲什么东西?
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-3-28 22:44 , Processed in 0.052479 second(s), 29 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表