void setup() { //Initalize the reader FlashDevice* device = Devices::createWearLevelErase(); FlashReader reader(device); Serial.begin(9600); Serial.println("Starting setup...."); //Wifi will be disabled at this point matrix.begin(); matrix.setTextWrap(false); matrix.setBrightness(100); matrix.setTextColor(matrix.Color(80,255,0)); matrix.fillScreen(0); //We're not connected to WIFI just yet but we need a number to show int salvations = reader.readInt(); //Show salvations unless something isn't stored in memory. if(salvations >= 0){ showSalvations(salvations, 0); }else{ matrix.print(F("******")); matrix.show(); } pinMode(batteryPin, INPUT_PULLUP); //Now that everything is done and being shown, lets quietly connect to wifi. if ( Spark.connected() == false){ Spark.connect(); } }
void timeExpired() { matrix.fillScreen(0); matrix.fillCircle(6, 6, 6, matrix.Color(190, 190, 190)); matrix.setTextColor(colors[0]); matrix.setCursor(0, 1); matrix.print(F("158")); if (counter % 2 == 0) { matrix.fillScreen(0); matrix.fillCircle(6, 5, 5, matrix.Color(20, 20, 20)); matrix.setTextColor(colors[2]); matrix.setCursor(0, 1); matrix.print(String(counter)); } matrix.show(); counter++; }
void loop() { unsigned long t = millis(); // Current elapsed time, milliseconds. // millis() comparisons are used rather than delay() so that animation // speed is consistent regardless of message length & other factors. BTLEserial.pollACI(); // Handle BTLE operations aci_evt_opcode_t state = BTLEserial.getState(); if(state != prevState) { // BTLE state change? switch(state) { // Change LED flashing to show state case ACI_EVT_DEVICE_STARTED: LEDperiod = 1000L / 10; break; case ACI_EVT_CONNECTED: LEDperiod = 1000L / 2; break; case ACI_EVT_DISCONNECTED: LEDperiod = 0L; break; } prevState = state; prevLEDtime = t; LEDstate = LOW; // Any state change resets LED digitalWrite(LED, LEDstate); } if(LEDperiod && ((t - prevLEDtime) >= LEDperiod)) { // Handle LED flash prevLEDtime = t; LEDstate = !LEDstate; digitalWrite(LED, LEDstate); } // If connected, check for input from BTLE... if((state == ACI_EVT_CONNECTED) && BTLEserial.available()) { if(BTLEserial.peek() == '#') { // Color commands start with '#' char color[7]; switch(readStr(color, sizeof(color))) { case 4: // #RGB 4/4/4 RGB matrix.setTextColor(matrix.Color( unhex(color[1]) * 17, // Expand to 8/8/8 unhex(color[2]) * 17, unhex(color[3]) * 17)); break; case 5: // #XXXX 5/6/5 RGB matrix.setTextColor( (unhex(color[1]) << 12) + (unhex(color[2]) << 8) + (unhex(color[3]) << 4) + unhex(color[4])); break; case 7: // #RRGGBB 8/8/8 RGB matrix.setTextColor(matrix.Color( (unhex(color[1]) << 4) + unhex(color[2]), (unhex(color[3]) << 4) + unhex(color[4]), (unhex(color[5]) << 4) + unhex(color[6]))); break; } } else { // Not color, must be message string msgLen = readStr(msg, sizeof(msg)-1); msg[msgLen] = 0; msgX = matrix.width(); // Reset scrolling } } if((t - prevFrameTime) >= (1000L / FPS)) { // Handle scrolling matrix.fillScreen(0); matrix.setCursor(msgX, 0); matrix.print(msg); if(--msgX < (msgLen * -6)) msgX = matrix.width(); // We must repeat! matrix.show(); prevFrameTime = t; } }
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) // NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) // NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) // Example for NeoPixel Shield. In this application we'd like to use it // as a 5x8 tall matrix, with the USB port positioned at the top of the // Arduino. When held that way, the first pixel is at the top right, and // lines are arranged in columns, progressive order. The shield uses // 800 KHz (v2) pixels that expect GRB color data. Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(16, 16, PIN, NEO_MATRIX_TOP + NEO_MATRIX_LEFT + NEO_MATRIX_COLUMNS + NEO_MATRIX_ZIGZAG, NEO_GRB + NEO_KHZ800); const uint16_t colors[] = { matrix.Color(255, 0, 0), matrix.Color(0, 255, 0), matrix.Color(0, 0, 255) }; int x = matrix.width(); int pass = 0; int counter = 1; class LoopTimerAdapter : public TimerAdapter { public: void timeExpired() { matrix.fillScreen(0); matrix.fillCircle(6, 6, 6, matrix.Color(190, 190, 190)); matrix.setTextColor(colors[0]); matrix.setCursor(0, 1);