Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.40 KB | None | 0 0
  1. //---------------------------------------------------------------------------
  2. //Adafruit Circuit Playground - Class Scheduler
  3. // Eduardo Rivero - March 2016
  4. // for Kingdom Academy Project Design
  5. //---------------------------------------------------------------------------
  6. //
  7. //---------------------------------------------------------------------------
  8. //How it works
  9. //NeoPixels 0-6 are used to indicate the class schedule by
  10. //period (position) and subject (color).
  11. //NeoPixels 8-9 show which block schedule is indicated.
  12. // ---------------------------------------------------------------------------
  13. //Setup
  14. //Set schedule (subject per period per day of the week)
  15. //variables at top of sketch in the schedule matrix.
  16. //Upload the sketch to Circuit Playground.
  17. //
  18. //Usage
  19. //Flip the toggle switch to the right to show display, left to hide it
  20. //Press right momentary button to change day of the week
  21. //Press left momentary button to change class period
  22. // ----------------------------------------------------------------------------
  23.  
  24. #include <Adafruit_CircuitPlayground.h>
  25. #include <Wire.h>
  26. #include <SPI.h>
  27.  
  28. // NUM_CLASSES is the number of class periods in a day
  29. // You could adjust this -- may be fewer than 5 but not greater
  30. // without running into the day-of-the-week pixels -- and you'd also
  31. // need to adjust the "schedule" and "classColor" matrices below
  32.  
  33. const int NUM_CLASSES = 5;
  34.  
  35. //*******************************************************
  36. // Adjust this "classColor" matrix to pick your own colors expressed
  37. // as RGB value triplets from 0-255 per class subject
  38. //*******************************************************
  39.  
  40. int classColor[NUM_CLASSES][3] = {
  41. {255, 0, 0}, // chorus is red
  42. { 0,255, 0}, // science is green
  43. { 255,0,255}, // history is purple
  44. { 0, 0,255}, // math is blue
  45. {255,255, 0} // english is yellow
  46. };
  47.  
  48. //*******************************************************
  49. //Adjust this "schedule" matrix to reflect your own class schedule
  50. //*******************************************************
  51.  
  52. const int NUM_DAYS = 5;
  53. int schedule[NUM_DAYS][NUM_CLASSES] = {
  54. {0,1,2,3,4}, // Monday = chorus, science, history, math, english
  55. {0,4,1,2,3}, // Tuesday = chorus, english, science, history, math
  56. {0,3,4,1,2}, // Wednesday = chorus, math, english, science, history
  57. {0,2,3,4,1}, // Thursday = chorus, history, math, english, science
  58. {0,1,2,3,4} // Friday = chorus, science, history, math, english
  59. };
  60.  
  61. // Global variables that track the current day and current period.
  62.  
  63. int period = 0;
  64. int day = 0;
  65.  
  66.  
  67.  
  68. void setup() {
  69. CircuitPlayground.begin(); //initialize the board
  70. CircuitPlayground.playTone(932,200); //startup beep frequency and duration
  71. //pulse the red LED twice
  72. int i=0;
  73. for(i=0;i<2;i++){
  74. CircuitPlayground.redLED(true);
  75. delay(200);
  76. CircuitPlayground.redLED(false);
  77. delay(200);
  78. }
  79. //fairly dim NeoPixel brightness setting -- goes up to a blinding 255!
  80. CircuitPlayground.setBrightness(15);
  81. CircuitPlayground.clearPixels(); //turns off all NeoPixels
  82. }
  83.  
  84.  
  85. void loop() {
  86.  
  87. //check the slide switch, "off" to the right means the buttons
  88. //won't respond, acting like they are locked, and turning off the
  89. //NeoPixels to save power/avoid annoying people, "on" to the left
  90.  
  91. if (!CircuitPlayground.slideSwitch()) {
  92. CircuitPlayground.clearPixels();
  93. return;
  94. }
  95.  
  96. // ------------------------------------------------------------------------
  97. // Detect if the left or right button is released by taking two
  98. // readings with a small delay in between. If the button changes
  99. // state from pressed -> released then we can update indicators.
  100.  
  101. bool leftFirst = CircuitPlayground.leftButton();
  102. bool rightFirst = CircuitPlayground.rightButton();
  103. delay(10);
  104. bool leftSecond = CircuitPlayground.leftButton();
  105. bool rightSecond = CircuitPlayground.rightButton();
  106.  
  107. // Read the day of the week (right) button, if pressed, increment
  108. // the "day" variable
  109. //"day" is an integer to represent the day of week 0-4 / M-F
  110. //starts on Monday which is index 0
  111.  
  112. if (rightFirst && !rightSecond){
  113. day++;
  114. //cycles from friday back to monday
  115. if (day > NUM_DAYS - 1) {
  116. day=0;
  117. }
  118. }
  119.  
  120. // Read the class period (left) button, if pressed, increment the
  121. // "period" variable
  122.  
  123. // "period" is the class period counter to indicate current period
  124. // starts on 1st period, which is index 0
  125.  
  126. if (leftFirst && !leftSecond){
  127. period++;
  128. //cycles from first to fifth period
  129. if (period > NUM_CLASSES -1) {
  130. period=0;
  131. }
  132. }
  133.  
  134. // ------------------------------------------------------------------------
  135. // Now we're ready to update display with day/period.
  136.  
  137. // Start by turning everything off
  138.  
  139. CircuitPlayground.clearPixels();
  140.  
  141. // Light up the day of the week pixel
  142.  
  143. CircuitPlayground.setPixelColor((9-day), 255, 255, 255);
  144.  
  145. // Light up the proper color for the class subject
  146.  
  147. CircuitPlayground.setPixelColor(period,
  148. (classColor[(schedule[day][period])][0]),
  149. (classColor[(schedule[day][period])][1]) ,
  150. (classColor[(schedule[day][period])][2])) ;
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement