Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //---------------------------------------------------------------------------
- //Adafruit Circuit Playground - Class Scheduler
- // Eduardo Rivero - March 2016
- // for Kingdom Academy Project Design
- //---------------------------------------------------------------------------
- //
- //---------------------------------------------------------------------------
- //How it works
- //NeoPixels 0-6 are used to indicate the class schedule by
- //period (position) and subject (color).
- //NeoPixels 8-9 show which block schedule is indicated.
- // ---------------------------------------------------------------------------
- //Setup
- //Set schedule (subject per period per day of the week)
- //variables at top of sketch in the schedule matrix.
- //Upload the sketch to Circuit Playground.
- //
- //Usage
- //Flip the toggle switch to the right to show display, left to hide it
- //Press right momentary button to change day of the week
- //Press left momentary button to change class period
- // ----------------------------------------------------------------------------
- #include <Adafruit_CircuitPlayground.h>
- #include <Wire.h>
- #include <SPI.h>
- // NUM_CLASSES is the number of class periods in a day
- // You could adjust this -- may be fewer than 5 but not greater
- // without running into the day-of-the-week pixels -- and you'd also
- // need to adjust the "schedule" and "classColor" matrices below
- const int NUM_CLASSES = 5;
- //*******************************************************
- // Adjust this "classColor" matrix to pick your own colors expressed
- // as RGB value triplets from 0-255 per class subject
- //*******************************************************
- int classColor[NUM_CLASSES][3] = {
- {255, 0, 0}, // chorus is red
- { 0,255, 0}, // science is green
- { 255,0,255}, // history is purple
- { 0, 0,255}, // math is blue
- {255,255, 0} // english is yellow
- };
- //*******************************************************
- //Adjust this "schedule" matrix to reflect your own class schedule
- //*******************************************************
- const int NUM_DAYS = 5;
- int schedule[NUM_DAYS][NUM_CLASSES] = {
- {0,1,2,3,4}, // Monday = chorus, science, history, math, english
- {0,4,1,2,3}, // Tuesday = chorus, english, science, history, math
- {0,3,4,1,2}, // Wednesday = chorus, math, english, science, history
- {0,2,3,4,1}, // Thursday = chorus, history, math, english, science
- {0,1,2,3,4} // Friday = chorus, science, history, math, english
- };
- // Global variables that track the current day and current period.
- int period = 0;
- int day = 0;
- void setup() {
- CircuitPlayground.begin(); //initialize the board
- CircuitPlayground.playTone(932,200); //startup beep frequency and duration
- //pulse the red LED twice
- int i=0;
- for(i=0;i<2;i++){
- CircuitPlayground.redLED(true);
- delay(200);
- CircuitPlayground.redLED(false);
- delay(200);
- }
- //fairly dim NeoPixel brightness setting -- goes up to a blinding 255!
- CircuitPlayground.setBrightness(15);
- CircuitPlayground.clearPixels(); //turns off all NeoPixels
- }
- void loop() {
- //check the slide switch, "off" to the right means the buttons
- //won't respond, acting like they are locked, and turning off the
- //NeoPixels to save power/avoid annoying people, "on" to the left
- if (!CircuitPlayground.slideSwitch()) {
- CircuitPlayground.clearPixels();
- return;
- }
- // ------------------------------------------------------------------------
- // Detect if the left or right button is released by taking two
- // readings with a small delay in between. If the button changes
- // state from pressed -> released then we can update indicators.
- bool leftFirst = CircuitPlayground.leftButton();
- bool rightFirst = CircuitPlayground.rightButton();
- delay(10);
- bool leftSecond = CircuitPlayground.leftButton();
- bool rightSecond = CircuitPlayground.rightButton();
- // Read the day of the week (right) button, if pressed, increment
- // the "day" variable
- //"day" is an integer to represent the day of week 0-4 / M-F
- //starts on Monday which is index 0
- if (rightFirst && !rightSecond){
- day++;
- //cycles from friday back to monday
- if (day > NUM_DAYS - 1) {
- day=0;
- }
- }
- // Read the class period (left) button, if pressed, increment the
- // "period" variable
- // "period" is the class period counter to indicate current period
- // starts on 1st period, which is index 0
- if (leftFirst && !leftSecond){
- period++;
- //cycles from first to fifth period
- if (period > NUM_CLASSES -1) {
- period=0;
- }
- }
- // ------------------------------------------------------------------------
- // Now we're ready to update display with day/period.
- // Start by turning everything off
- CircuitPlayground.clearPixels();
- // Light up the day of the week pixel
- CircuitPlayground.setPixelColor((9-day), 255, 255, 255);
- // Light up the proper color for the class subject
- CircuitPlayground.setPixelColor(period,
- (classColor[(schedule[day][period])][0]),
- (classColor[(schedule[day][period])][1]) ,
- (classColor[(schedule[day][period])][2])) ;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement