Advertisement
estephan500

Untitled

Oct 23rd, 2019
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 19.69 KB | None | 0 0
  1.  
  2. // NOW FIXED IF THIS IS INDEED THE INSTALLED VERSION.
  3. // LONGPRESSGREEN to start time edit. then:
  4. //      * press blue to move hour back one (rarely needed)
  5. //      * press red to move minute back one (usual case)
  6. //      * when done, press yellow to end edit mode.
  7. // DO THIS RIGHT AFTER THE BEGINNING OF THE MINUTE, SINCE IT WILL SEND IT TO :00 SECONDS.
  8. // IN PROGRESS NOT FULLY WORKING PROBABLY TRYING TO FIX SHORT MINUTES DIGIT IN YELLOW. will test over time.
  9.  
  10. // 10.0 now need to fix bugs that (1) z0 and z1 screw up the light pattern, (2) song gets nuked now somehow? // FIXED IT A BIT FOR NOW
  11.  
  12. // 9.9 currently under development. ***SEEMS TO WORK NOW! searching for a way to modify clock time with buttons.
  13. // 9.85 works fine, made motor spin buzz longer and disabled floor cleanup chime at 5:45
  14. // 9.8 making yellw button show time on 8x8
  15. // trying to make the ball bounce nicer
  16. // still seems to be newest now that it's 22 march 2017, we'll see.
  17. // also installed on 29 june 2018!! current as of then
  18.  
  19. // RTC RESET RERUN THEN PLUG IN NEW TIME ~ ~ 57600baud ~ ~ HOW TO DO IT?  
  20. // take out battery from clock.
  21. // make only power be from computer.
  22. // make a change to the app and save it.    
  23. // unplug usb so arduino turns off.
  24. // FAST compile app with the check mark icon.
  25. // FAST plug in USB immediately (hopefully not need to reset port.) it will bleeeep.
  26. // [And set its time to... last compiled time? god knows]
  27. // FAST and do an upload with the arrow button.
  28. // then while running, place battery back into clock.
  29. // then maybe do one more usb upload?
  30.  
  31. // RTC from RTC examples, see built in to IDC
  32. #include <Wire.h>
  33. #include "RTClib.h"
  34.  
  35. #include <Time.h> // NOT PUT IN
  36. //#include <DS1307RTC.h> // NOT PUT IN
  37. #include "pitches.h"
  38. #include "Adafruit_LEDBackpack.h"
  39. #include "Adafruit_GFX.h"
  40.  
  41. // FORTHECOLORONE  Adafruit_BicolorMatrix matrix = Adafruit_BicolorMatrix();
  42.  
  43. Adafruit_8x8matrix matrix = Adafruit_8x8matrix();
  44.  
  45. // RTC head stuff =========================
  46.  
  47. // removed this array for memory --- char daysOfTheWeek[7][1] = {"S", "M", "T", "W", "h", "F", "a"};
  48.  
  49. #if defined(ARDUINO_ARCH_SAMD)
  50. // for Zero, output on USB Serial console, remove line below if using programming port to program the Zero!
  51.    #define Serial SerialUSB
  52. #endif
  53.  
  54. RTC_DS1307 rtc;  
  55.  
  56. // end RTC head stuff ======================
  57.  
  58.  
  59. // eric song book
  60.  
  61. int maxsongs = 11; //make this be one greater than the index number of the highest song. if songs number from 0-5, maxsongs should be 6. popsong will skip the first one(s) as reserved as not "songs"
  62.  
  63. // first the note tones
  64. int songsnotes[11][25] = {
  65.   {g3,ds3,f3,as2,0,as2,f3,g3,ds3},
  66.   {b3,gs3,e3,cs3},
  67.   {as3,a3,as3,a3,as3,c4,d4,e4,f4},
  68.   {a3,as3,c4,as3,a3,g3,f3,e3,ds3,f3,g3,a3,as3,fs3,f3,ds3},
  69.   {g3, g3, g2, g2, g3, g3, f3, f3, f2, f2, f3, f3, ds3, ds3, ds2, ds2, ds3, ds3, a2, as2,c3,as2,a2,as2,g2 },
  70.   {e3,e3,0,a3,a3,0,d3,d3,g3,g3,fs3,e3,e3,a3,gs3,b3,b3,g3,g3,fs3,fs3},
  71.   {f3,f3,ds3,f3,0,c3,0,c3,f3,as3,a3,f3 },
  72.   {c2,d2,e2,f2,0,g2,a2,as2,c3,0,d3,e3,f3,e3,0,d3,c3,as2,c3},
  73.   {c3,c4,a3,c3,c4,a3,f3,d4,c4,c4,as3,a3,g3,as3,g3,f3,e3,f3},
  74.   {e3,d3,e3,0,d3,c3,b2,a2,gs2,a2},
  75.   {g3,b3,cs4,e4,d4,b3,g3,e3,cs3,cs3,cs3,d3}
  76. };
  77.  
  78. // then the durations
  79. int songslengths[11][26] = {
  80.   {2,2,2,1,4,2,2,2,1,999},  // reserved big ben
  81.   {2,2,2,1,999},  //reserved
  82.   {16,16,16,16,16,16,16,16,4,999}, // quickie
  83.   {4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,999}, // psycho
  84.   {8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,2,999}, // chungking express
  85.   {4,4,8,8,8,8,4,3,8,8,8,    3,8,4,4,3,8,8,8,8,8,999}, // futurama
  86.   {8,8,8,8,8,8,8,8,8,8,8,8 ,999}, // funky town
  87.   {8,8,8,2,8,8,8,8,2,8,8,8,8,2,8,8,8,8,2,999}, // cinema paradiso
  88.   {8,8,4,8,8,4,4,8,8,8,8,4,8,16,16,8,8,4}, // tune odd
  89.   {16,16,2,4,6,6,6,6,2,1},  // fugue
  90.   {4,8,8,16,4,8,8,16,16,16,16,8} // simpsons
  91. };
  92.  
  93.  
  94. const int reservedsongs = 2;
  95. const int bulb[] = {9,6,11,10};  // originally 13,12,11,10. want this to be 9,6,11,10
  96. const int bttn[] = {13,8,7,12};  // originally 9,8,7,6. want this to be 13,8,7,12
  97. const int keysound[] = {65,82,98,131};
  98. const int speaker = 5;
  99. const int analogpot = 1;
  100.  
  101. // int pattern;
  102. int lengthdelay =250;
  103. int cyclenumber=10;
  104. int counter=1;
  105. int counterout=1;
  106. int counterin=1;
  107. const int motor=3;
  108. float ballx=5.0;
  109. float bally=2.0;
  110. float ballyvel=0.1;
  111. float ballxvel=0.6;
  112. const int ballxmin = 0;
  113. const int ballxmax = 7;
  114. const int ballymin = 0;
  115. const int ballymax = 8;
  116. int utilinteger = 0;
  117. int z0=0;
  118. int z1=0;
  119. int z2=0;
  120. int z3=0;
  121.  
  122.  
  123. // END HEAD ==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==
  124.  
  125.  
  126. void note(int pitch, int len) {
  127.   int chop=1;
  128.   if (chop==1) {
  129.     tone(speaker, pitch, len);
  130.     delay(len*1.3);
  131.   }
  132.     else {
  133.       for(int ccc = 0; ccc<chop; ccc++) {
  134.         tone(speaker, pitch, len/chop);
  135.         delay((len/chop));
  136.       }
  137.     delay(len/chop);
  138.     }
  139. }
  140.  
  141.  
  142.  
  143. void sayhi() {
  144.     note(gs3,250);
  145.     note(e3,100);
  146.     note(e3,100);
  147. }
  148.  
  149. void pip() {
  150.     note(e3,100);
  151.     delay(100);
  152. }
  153.  
  154.  
  155. void sayhi2() {
  156.     note(e3,100);
  157.     note(gs3,150);
  158.     delay(70);
  159.     note(gs3,100);
  160.     note(b2,150);
  161.     delay(70);
  162.     note(gs3,100);
  163.     note(e3,250);
  164. }
  165.  
  166.  
  167.  
  168. void playsong(int whichsong) {
  169.  
  170. // iterate over the notes of the melody:
  171.    
  172.         for (int thisnote = 0; thisnote < 30; thisnote++) {
  173.  
  174.           // to calculate the note duration, take one second
  175.           // divided by the note type.
  176.           //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
  177.           int mult = map(analogRead(analogpot),0,1023,0.2,3) ;         //  ***  
  178.           int noteDuration = (1500 / songslengths[whichsong][thisnote]) * mult;
  179.          
  180.           if (noteDuration < 10) {
  181.             break;
  182.           }
  183.          
  184.           // disabling 3 steps so that this can call eric's note method
  185.           // tone(speaker, songsnotes[whichsong][thisnote], noteDuration);
  186.           // to distinguish the notes, set a minimum time between them.
  187.           // the note's duration + 30% seems to work well:
  188.           // int pauseBetweenNotes = noteDuration * 1.30;
  189.           // delay(pauseBetweenNotes);
  190.           note(songsnotes[whichsong][thisnote], noteDuration);
  191.  
  192.          
  193.           noTone(speaker);
  194.         }
  195.  
  196.  
  197. }
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204. void setup() {  // OOOOOOOOOOOOOOOO0000000000000000000000000000088888888000000OOOOOOOOOOOOOOOOO
  205.  
  206.   // RTC setup stuff
  207.  
  208.   int nonsense=2;
  209.  
  210.   #ifndef ESP8266
  211.     while (!Serial); // for Leonardo/Micro/Zero
  212.   #endif
  213.  
  214.   Serial.begin(57600);
  215.   randomSeed(analogRead(0));
  216.  
  217.   if (! rtc.begin()) {
  218.     Serial.println("Couldn't find RTC");
  219.     while (1);
  220.   }
  221.  
  222. // **++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**
  223.  
  224.   if (! rtc.isrunning())  {
  225.     Serial.println("RTC is  NOT  running!");
  226.     tone(speaker,131,600);
  227.     delay(602);
  228.     tone(speaker,131,100);
  229.     delay(20);
  230.     tone(speaker,101,500);
  231.     delay(20);
  232.     tone(speaker,131,100);
  233.     delay(20);
  234.     tone(speaker,200,900);
  235.     delay(20);
  236.     // following line sets the RTC to the date & time this sketch was compiled
  237.     rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  238.     // This line sets the RTC with an explicit date & time, for exxxample to set
  239.     // January 21, 2014 at 3am you would call:
  240.     // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
  241.   }
  242.  
  243.   // end RTC setup stuff
  244.  
  245.  
  246.  
  247.   matrix.begin(0x70);  // pass in the address, SAME IN COLOR OR NOT COLOR MODELS
  248.  
  249.      
  250.   pinMode(motor, OUTPUT);
  251.   pinMode(bulb[0],OUTPUT);
  252.   pinMode(bulb[1],OUTPUT);
  253.   pinMode(bulb[2],OUTPUT);
  254.   pinMode(bulb[3],OUTPUT);
  255.   pinMode(bttn[0],INPUT);
  256.   pinMode(bttn[1],INPUT);
  257.   pinMode(bttn[2],INPUT);
  258.   pinMode(bttn[3],INPUT);
  259.   pinMode(speaker, OUTPUT);
  260.    
  261.        
  262. }
  263.  
  264.  
  265. // END OF SETUP OOOOOOOOOOOOOOOO00000000000OOOOOO0000000000000000000000000000088
  266.  
  267. void climbditty(int level, int gap) {
  268.   note(level,100);
  269.   delay(80);
  270.   note(level,80);
  271.   delay(20);
  272.   note(level,80);
  273.   delay(10);
  274.   note(level+gap,125);
  275.   delay(10);
  276.   note(level,80);
  277.   delay(150);
  278. }
  279.  
  280. void showtext(String name) {
  281.   matrix.setTextSize(1);
  282.   matrix.setTextWrap(false);  // we dont want text to wrap so it scrolls nicely
  283.   matrix.setTextColor(LED_ON);
  284.   for (int8_t x=0; x>=-36; x--) {
  285.     matrix.clear();
  286.     matrix.setCursor(x,0);
  287.     matrix.print(" " + name);
  288.     matrix.writeDisplay();
  289.     delay(50);
  290.   }
  291. }
  292.  
  293. void climbsong() {
  294.   const int lowtone=100;
  295.   const int hightone=900;
  296.   String scorecountstring;
  297.   int scorecount=0;
  298.   int level=lowtone;
  299.   while (level<hightone) {
  300.     int gap=random(2,700);
  301.     climbditty(level,gap);
  302.     scorecount++;
  303.     level += gap;
  304.     }
  305.   buzz();
  306.   scorecountstring = String(scorecount);
  307.   showtext(scorecountstring);
  308. }
  309.  
  310.  
  311. void yay() {
  312.   note(g3,100);
  313.   delay(80);
  314.   note(g3,80);
  315.   delay(20);
  316.   note(g3,80);
  317.   delay(10);
  318.   note(c4,700);
  319. }
  320.  
  321.  
  322.  
  323. void boo() {
  324.   note(330,50);
  325.   delay(300);
  326.   note(e2,200);
  327.   delay(50);
  328.   note(c2,600);
  329. }
  330.  
  331. void compubabble(int howmany,int pace) {
  332.   for(int c=1; c<howmany+1;c++) {
  333.     int num=random(33,126);
  334.     char ch = num;
  335.     matrix.drawChar(2, 0,  ch, 255, 0, 1);
  336.     matrix.writeDisplay();
  337.     note(random(50,1500),pace);
  338.     //matrix clear it
  339.     matrix.clear();
  340.     matrix.writeDisplay();
  341.     //matrix end clear it
  342.   }
  343. }
  344.  
  345. // GAME GAME GAME STUFF FROM HERE *******
  346.  
  347.  
  348. void show(int key) {  // PART OF GAME
  349.    
  350.       digitalWrite(bulb[key],HIGH);
  351.       note(keysound[key],600);
  352.       digitalWrite(bulb[key],LOW);
  353.       delay(50);
  354.  
  355. }
  356.  
  357. int getinput() {     // PART OF GAME
  358.   int decision=9;
  359.  
  360.   // wait til press
  361.  
  362.   while (decision==9) {
  363.       if ( (digitalRead(bttn[0]) == HIGH) or (digitalRead(bttn[1]) == HIGH)  or (digitalRead(bttn[2]) == HIGH) or (digitalRead(bttn[3]) == HIGH ) ) {
  364.         if (digitalRead(bttn[0]) == HIGH) {
  365.           decision=0;
  366.         }
  367.         else if (digitalRead(bttn[1]) == HIGH) {
  368.           decision=1;
  369.         }
  370.         else if (digitalRead(bttn[2]) == HIGH) {
  371.           decision=2;
  372.         }
  373.         else if (digitalRead(bttn[3]) == HIGH) {
  374.           decision=3;
  375.         }
  376.       }
  377.   }
  378. show(decision);
  379. return decision;
  380. }
  381.  
  382.  
  383.  
  384.  
  385. boolean trial(int sequence[], int glength) {    // PART OF GAME
  386.   boolean dotheywin=true;
  387.   int guess;
  388.     for (int countx = 0; countx < glength; countx++) {  
  389.       guess=getinput();  
  390.       if (guess != sequence[countx]) { // kick out if wrong
  391.         dotheywin=false;
  392.         break;
  393.       }
  394.     }
  395.     // we have gone through the whole loop, or got kicked out
  396.   return dotheywin;
  397. }
  398.  
  399.  
  400.  
  401.  
  402.  
  403. void playgame() {        // PART OF GAME
  404.     int glength = 7;
  405.     int sequence[glength-1];
  406.  
  407.     boolean theywon;
  408.     flashblank(); // clear the lights to all off.
  409.     // tones to say let's start
  410.     delay(400);
  411.     note(e4,50);
  412.     delay(50);
  413.     note(e4,50);
  414.     delay(50);
  415.     note(e4,50);
  416.     delay(50);
  417.     delay(600);
  418.    
  419.     // define puzzle
  420.     for(int aa = 0; aa < glength; aa++) {
  421.         sequence[aa] = random(0,4);
  422.         }
  423.    
  424.     // play puzzle
  425.     for(int bb = 0; bb<glength; bb++) {
  426.         show(sequence[bb]);
  427.     }
  428.    
  429.     // loop for user to try to match it
  430.     theywon = trial(sequence,glength);
  431.  
  432.     // evaluate
  433.     if (theywon) {
  434.       yay();
  435.     }
  436.     else if (not theywon) {
  437.       boo();
  438.     }
  439.  
  440. }
  441.  
  442. // END GAME *****************************
  443.  
  444. int popsong(int whichsong) {
  445.       playsong(whichsong);
  446.       whichsong++;
  447.       if (whichsong == maxsongs) {
  448.         whichsong = reservedsongs;
  449.       }
  450. return whichsong;
  451. }
  452.  
  453.  
  454. void buzz() {
  455.   analogWrite(motor, 254);
  456.   delay(1000);
  457.   analogWrite(motor, 0);
  458.   delay(1);
  459. }
  460.  
  461. void flashmult(int r0, int r1, int r2, int r3) {
  462.   if (r0==1) {digitalWrite(bulb[0],HIGH); };
  463.   if (r1==1) {digitalWrite(bulb[1],HIGH); };
  464.   if (r2==1) {digitalWrite(bulb[2],HIGH); };
  465.   if (r3==1) {digitalWrite(bulb[3],HIGH); };
  466.   delay(lengthdelay/6);
  467. }
  468.  
  469. void flashblank() {
  470.   digitalWrite(bulb[0],LOW);
  471.   digitalWrite(bulb[1],LOW);
  472.   digitalWrite(bulb[2],LOW);
  473.   digitalWrite(bulb[3],LOW);
  474. }
  475.  
  476.  
  477.  
  478. void loop() {  // ****** *****  ***********  ******  **** **** ***** *****
  479.      
  480.     DateTime now = rtc.now();
  481.     int prevvalue = 99;
  482.     int prevminute = 99;
  483.     int songrotator = reservedsongs;  //XXXXXXX ROTATOR
  484.     boolean tempmuted = true;
  485.     boolean showpic = false;
  486.     String thestring;
  487.  
  488.     // OXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXO REAL LOOP
  489.     // OXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXO REAL LOOP
  490.     // OXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXO REAL LOOP  
  491.      
  492.       while (true) {
  493.        
  494.           // POTENTIOMETER INPUT ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  495.           lengthdelay = analogRead(analogpot);
  496.  
  497.           // DATE TIME STUFF  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  498.          
  499.           // dt cycletop
  500.           DateTime now = rtc.now();
  501.           int thishour=now.hour();
  502.           int thisminute=now.minute();
  503.           cyclenumber=thishour;
  504.          
  505.           // dt every hour detect and chime
  506.           if ((thishour != prevvalue) and ((thishour > 6) and (thishour < 21)  and (tempmuted != true) )) {
  507.             buzz();
  508.             // playsong(4); // play the big ben song if that's the method you prefer
  509.             songrotator = popsong(songrotator);
  510.             counter=1;
  511.             buzz();
  512.             // Serial.println('BEEPBEEPBEEP HOUR CHIME');
  513.             }
  514.           tempmuted = false; // avoids the first-time chime each time you upload the app
  515.  
  516.           // dt every 30min detect and chime
  517.           if((thisminute != prevminute) and (thisminute == 30) and ((thishour > 5) and (thishour < 21))) {
  518.             // here
  519.             note(e3,50);
  520.             delay(50);
  521.             note(e3,50);
  522.             buzz();
  523.             buzz();
  524.             buzz();
  525.             buzz();
  526.  
  527.            
  528.           }
  529.  
  530.           // dt CLEAN UP FLOOR TIME detect and chime **DISABLED WITH 1=2
  531.           if( (1==2) and (thisminute != prevminute) and (thisminute == 45) and (thishour == 17)) {
  532.             // here
  533.             buzz();
  534.             buzz();
  535.             buzz();
  536.             yay();
  537.             delay(500);
  538.             boo();
  539.             boo();
  540.             delay(500);
  541.             yay();
  542.             buzz();
  543.             buzz();
  544.             buzz();
  545.           }
  546.  
  547.           // dt cyclebottom
  548.           prevvalue=thishour;
  549.           prevminute=thisminute;
  550.          
  551.           // LIGHTS SHOW  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  552.          
  553.           if ((counter % cyclenumber)==0) {
  554.          
  555.             flashblank();
  556.             if (counterin%1==0) { z3 = !z3;};  
  557.             if (counterin%2==0) { z2 = !z2;};
  558.             if (counterin%4==0) { z1 = !z1;};
  559.             if (counterin%8==0) { z0 = !z0;};
  560.             flashmult(z0,z1,z2,z3);  
  561.             counterin++;
  562.           }
  563.          
  564.  
  565.           // BUTTON INPUT BY USER  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  566.          
  567.           // BUTTON-BLUE
  568.           while (digitalRead(bttn[0]) == HIGH )  {  
  569.             playgame();
  570.           }
  571.          
  572.           // BUTTON-RED
  573.           while (digitalRead(bttn[1]) == HIGH )  {
  574.             climbsong();
  575.           }
  576.  
  577.           // BUTTON-YELLOW
  578.           while (digitalRead(bttn[2]) == HIGH )  {  
  579.            
  580.             compubabble(5,70);  
  581.             delay(600);
  582.             compubabble(9,70);  
  583.                
  584.               DateTime now = rtc.now();
  585.               // UN-COMMENT BELOW IF YOU CARE ABOUT PRINTLN TO SERIAL
  586.               //Serial.print(now.year(), DEC);
  587.               //Serial.print('/');
  588.               //Serial.print(now.month(), DEC);
  589.               //Serial.print('/');
  590.               //Serial.print(now.day(), DEC);
  591.               //Serial.print(" (");
  592.               // Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
  593.               //Serial.print(now.dayOfTheWeek());   // made this instead of above one
  594.               //Serial.print(") ");
  595.               //Serial.print(now.hour(), DEC);
  596.               //Serial.print(':');
  597.               //Serial.print(now.minute(), DEC);
  598.               //Serial.print(':');
  599.               //Serial.print(now.second(), DEC);
  600.               //Serial.println();
  601.               //Serial.println('counter is');
  602.               //Serial.println(counter);
  603.               //Serial.println('cyclenumber is');
  604.               //Serial.println(cyclenumber);
  605.               //Serial.println('thishour is');
  606.               //Serial.println(thishour);
  607.               // end rtc stuff
  608.               // showtext(F(__DATE__));
  609.               // thestring='----now--';
  610.               // showtext(thestring);
  611.               // ***** soon will use this: String.format("%02d", myNumber)
  612.               // ***** backing up old string: thestring = String(now.hour()) + ":" + String(now.minute()) ;
  613.               thestring = String(now.hour()) + ":" ;
  614.              
  615.               if (strlen(now.minute()) < 2) {
  616.                 thestring = thestring + "0";
  617.               }
  618.               thestring = thestring + String(now.minute()) ;
  619.               showtext(thestring);
  620.              
  621.           }
  622.  
  623.           // BUTTON-GREEN
  624.           while (digitalRead(bttn[3]) == HIGH )  {
  625.               // sing a damn song and we will see if user is still holding green afterwards
  626.               songrotator = popsong(songrotator);
  627.               // sayhi2();
  628.               while (digitalRead(bttn[3]) == HIGH )  { // GREEN STILL ON we are doing the NEW TIME FIX INTERFACE
  629.                 sayhi();
  630.                 // 1 STORE THE hour and minute
  631.                 z0 = now.hour();
  632.                 z1 = now.minute();
  633.                 utilinteger = 1; //set to zero when time to exit interface
  634.                 while (utilinteger == 1) {
  635.                   while (digitalRead(bttn[0]) == HIGH )  { // BLUE means hour backwards
  636.                     z0 = z0 - 1;
  637.                     if (z0 < 0) {
  638.                       z0 = 23;
  639.                     }
  640.                     pip();
  641.                   }
  642.                   while (digitalRead(bttn[1]) == HIGH )  { // RED means min backwards
  643.                     z1 = z1 - 1;
  644.                     if (z1 < 0) {
  645.                       z1 = 59;
  646.                     }
  647.                     pip();
  648.                   }
  649.                   while (digitalRead(bttn[2]) == HIGH )  { // YELLOW means exit interface
  650.                     pip();
  651.                     pip();
  652.                     utilinteger = 0;
  653.                   } // end yellow
  654.              
  655.                 } // leaving = they pressed yellow so end interface
  656.                 rtc.adjust(DateTime(now.year(), now.month(), now.day(), z0, z1, 0));
  657.                 z0 = 0;
  658.                 z1 = 0;
  659.                 z2 = 0;
  660.                 z3 = 0;
  661.                
  662.               } // leaving = they did not hold green or timeset is dome
  663.              
  664.           } // OK finished the initial green
  665.  
  666.           // MATRIX GRID ball bounce MAXXSHOW  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  667.  
  668.           ballyvel = ballyvel + 0.5;
  669.           bally = bally + ballyvel;
  670.           ballx = ballx + ballxvel;
  671.  
  672.           if (bally > ballymax) {
  673.             bally = bally - ballyvel;
  674.             ballyvel = 0-ballyvel;
  675.           }
  676.  
  677.           if (ballx > ballxmax or ballx < ballxmin) {
  678.             ballx = ballx - ballxvel;
  679.             ballxvel = 0- ballxvel;
  680.             //matrix clear it
  681.             // matrix.clear(); CLEAR ONLY PER PAGE METHOD
  682.             // matrix.writeDisplay();
  683.             //matrix end clear it
  684.           }
  685.  
  686.           //matrix draw it
  687.           // matrix.drawRect(int(ballx),int(bally),2,2, LED_ON);
  688.           matrix.clear();
  689.           matrix.drawPixel(int(ballx),int(bally),  LED_ON);
  690.           matrix.writeDisplay();
  691.  
  692.  
  693.           // matrix end
  694.           delay(lengthdelay/8);
  695.           counter++;
  696.          
  697.          
  698.       }  // END  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ end the inner infinite repeat loop
  699.  
  700. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement