Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Arduino Bluetooth Periodiek Systeem
#include <SoftwareSerial.h> #include <Adafruit_NeoPixel.h> #ifdef __AVR__ #include <avr/power.h> #endif SoftwareSerial BT(10, 11); // TX, RX of the Bluetooth Module #define PIXEL_PIN 12 // Data Pin of Led strip #define PIXEL_COUNT 24 // Number of LEDs in the strip #define BRIGHTNESS 250 // use 96 for medium brightness #define SPEED 0 // Speed of each Color Transition (in ms) #define IMMEDIATELY 0 // Transition happen instantly #define RAINBOW_SPEED 150 // Rainbow Transition speed Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800); bool offOld = LOW; bool R1Old = LOW; bool R2Old = LOW; bool R3Old = LOW; bool R4Old = LOW; bool R5Old = LOW; bool R6Old = LOW; bool R7Old = LOW; bool K1Old = LOW; bool K2Old = LOW; bool K3Old = LOW; bool K4Old = LOW; bool K5Old = LOW; bool K6Old = LOW; bool K7Old = LOW; bool K8Old = LOW; bool K9Old = LOW; bool K10Old = LOW; bool K11Old = LOW; bool K12Old = LOW; bool K13Old = LOW; bool K14Old = LOW; bool K15Old = LOW; bool K16Old = LOW; bool K17Old = LOW; bool K18Old = LOW; //effects bool RainbowOld = LOW; int showType = 0; void setup() { BT.begin(9600); BT.println("Connected to Arduino"); strip.setBrightness(BRIGHTNESS); strip.begin(); strip.show(); } char a; void loop() { bool off = LOW; bool R1 = LOW; bool R2 = LOW; bool R3 = LOW; bool R4 = LOW; bool R5 = LOW; bool R6 = LOW; bool R7 = LOW; bool K1 = LOW; bool K2 = LOW; bool K3 = LOW; bool K4 = LOW; bool K5 = LOW; bool K6 = LOW; bool K7 = LOW; bool K8 = LOW; bool K9 = LOW; bool K10 = LOW; bool K11 = LOW; bool K12 = LOW; bool K13 = LOW; bool K14 = LOW; bool K15 = LOW; bool K16 = LOW; bool K17 = LOW; bool K18 = LOW; // effects bool Rainbow = LOW; bool ende; if (BT.available()) { a= (char)BT.read(); if(a=='0') { off = HIGH; BT.println("TURNING OFF LEDs.."); }else{ off = LOW; } // =============================================PERIODES====================================== if(a=='1') { R1 = HIGH; BT.println("Periode 1 geselecteerd"); }else{ R1 = LOW; } // =========================================================================================== if(a=='2') { R2 = HIGH; BT.println("Periode 2 geselecteerd"); }else{ R2 = LOW; } // =========================================================================================== if(a=='3') { R3 = HIGH; BT.println("Periode 3 geselecteerd"); }else{ R3 = LOW; } // =========================================================================================== if(a=='4') { R4 = HIGH; BT.println("Periode 4 geselecteerd"); }else{ R4 = LOW; } // =========================================================================================== if(a=='5') { R5 = HIGH; BT.println("Periode 5 geselecteerd"); }else{ R5 = LOW; } // =========================================================================================== if(a=='6') { R6 = HIGH; BT.println("Periode 6 geselecteerd"); }else{ R6 = LOW; } // =========================================================================================== if(a=='7') { R7 = HIGH; BT.println("Periode 7 geselecteerd"); }else{ R7 = LOW; } // =========================================================================================== // ================================================GROEPEN===================================== if(a=='a') { K1 = HIGH; BT.println("Groep Ia geselecteerd"); }else{ K1 = LOW; } // =========================================================================================== if(a=='b') { K2 = HIGH; BT.println("Periode IIa geselecteerd"); }else{ K2 = LOW; } // =========================================================================================== if(a=='c') { K3 = HIGH; BT.println("Groep IIIb geselecteerd"); }else{ K1 = LOW; } // =========================================================================================== if(a=='d') { K4 = HIGH; BT.println("Groep IVb geselecteerd"); }else{ K1 = LOW; } // =========================================================================================== if(a=='a') { K5 = HIGH; BT.println("Groep Vb geselecteerd"); }else{ K1 = LOW; } // =========================================================================================== if(a=='e') { K6 = HIGH; BT.println("Groep VIb geselecteerd"); }else{ K1 = LOW; } // =========================================================================================== if(a=='f') { K7 = HIGH; BT.println("Groep VIIb geselecteerd"); }else{ K1 = LOW; } // =========================================================================================== if(a=='g') { K8 = HIGH; BT.println("Groep VIIIb (1) geselecteerd"); }else{ K1 = LOW; } // =========================================================================================== if(a=='h') { K9 = HIGH; BT.println("Groep VIIIb (2) geselecteerd"); }else{ K1 = LOW; } // =========================================================================================== if(a=='i') { K10 = HIGH; BT.println("Groep VIIIb (3) geselecteerd"); }else{ K1 = LOW; } // =========================================================================================== if(a=='j') { K11 = HIGH; BT.println("Groep Ib geselecteerd"); }else{ K1 = LOW; } // =========================================================================================== if(a=='k') { K12 = HIGH; BT.println("Groep IIb geselecteerd"); }else{ K1 = LOW; } // =========================================================================================== if(a=='l') { K13 = HIGH; BT.println("Groep IIIa geselecteerd"); }else{ K1 = LOW; } // =========================================================================================== if(a=='m') { K14 = HIGH; BT.println("Groep IVa geselecteerd"); }else{ K1 = LOW; } // =========================================================================================== if(a=='n') { K15 = HIGH; BT.println("Groep Va geselecteerd"); }else{ K1 = LOW; } // =========================================================================================== if(a=='o') { K16 = HIGH; BT.println("Groep VIa geselecteerd"); }else{ K1 = LOW; } // =========================================================================================== if(a=='p') { K17 = HIGH; BT.println("Groep VIIa geselecteerd"); }else{ K1 = LOW; } // =========================================================================================== if(a=='q') { K18 = HIGH; BT.println("Groep 0 geselecteerd"); }else{ K1 = LOW; } // =========================================================================================== if(a=='r') { Rainbow = HIGH; BT.println("Start Regenboog Effect"); }else{ Rainbow = LOW; } // =/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/= } if (off == LOW && offOld == HIGH) { delay(20); if (off == LOW) { showType = 0 ; // Off animation Type 0 startShow(showType); } } // =========================================================================================== // =========================================================================================== if (R1 == LOW && R1Old == HIGH) { delay(20); if (R1 == LOW) { showType = 1 ; startShow(showType); } } // =========================================================================================== if (R2 == LOW && R2Old == HIGH) { delay(20); if (R2 == LOW) { showType = 2 ; startShow(showType); } } // =========================================================================================== if (R3 == LOW && R3Old == HIGH) { delay(20); if (R3 == LOW) { showType = 3 ; startShow(showType); } } // =========================================================================================== if (R4 == LOW && R4Old == HIGH) { delay(20); if (R4 == LOW) { showType = 4 ; startShow(showType); } } // =========================================================================================== if (R5 == LOW && R5Old == HIGH) { delay(20); if (R5 == LOW) { showType = 5 ; startShow(showType); } } // =========================================================================================== if (R6 == LOW && R6Old == HIGH) { delay(20); if (R6 == LOW) { showType = 6 ; startShow(showType); } } // =========================================================================================== if (R7 == LOW && R7Old == HIGH) { delay(20); if (R1 == LOW) { showType = 7 ; startShow(showType); } } // =========================================================================================== if (K1 == LOW && K1Old == HIGH) { delay(20); if (K1 == LOW) { showType = 8 ; startShow(showType); } } // =========================================================================================== if (K2 == LOW && K2Old == HIGH) { delay(20); if (K2 == LOW) { showType = 9 ; startShow(showType); } } // =========================================================================================== if (K3 == LOW && K3Old == HIGH) { delay(20); if (K3 == LOW) { showType = 10 ; startShow(showType); } } // =========================================================================================== if (K4 == LOW && K4Old == HIGH) { delay(20); if (K4 == LOW) { showType = 11 ; startShow(showType); } } // =========================================================================================== if (K5 == LOW && K5Old == HIGH) { delay(20); if (K5 == LOW) { showType = 12 ; startShow(showType); } } // =========================================================================================== if (K6 == LOW && K6Old == HIGH) { delay(20); if (K6 == LOW) { showType = 13 ; startShow(showType); } } // =========================================================================================== if (K7 == LOW && K7Old == HIGH) { delay(20); if (K7 == LOW) { showType = 14 ; startShow(showType); } } // =========================================================================================== if (K8 == LOW && K8Old == HIGH) { delay(20); if (K8 == LOW) { showType = 15 ; startShow(showType); } } // =========================================================================================== if (K9 == LOW && K9Old == HIGH) { delay(20); if (K9 == LOW) { showType = 16 ; startShow(showType); } } // =========================================================================================== if (K10 == LOW && K10Old == HIGH) { delay(20); if (K10 == LOW) { showType = 17 ; startShow(showType); } } // =========================================================================================== if (K11 == LOW && K11Old == HIGH) { delay(20); if (K11 == LOW) { showType = 18 ; startShow(showType); } } // =========================================================================================== if (K12 == LOW && K12Old == HIGH) { delay(20); if (K12 == LOW) { showType = 19 ; startShow(showType); } } // =========================================================================================== if (K13 == LOW && K13Old == HIGH) { delay(20); if (K13 == LOW) { showType = 20 ; startShow(showType); } } // =========================================================================================== if (K14 == LOW && K14Old == HIGH) { delay(20); if (K14 == LOW) { showType = 21 ; startShow(showType); } } // =========================================================================================== if (K15 == LOW && K15Old == HIGH) { delay(20); if (K15 == LOW) { showType = 22 ; startShow(showType); } } // =========================================================================================== if (K16 == LOW && K16Old == HIGH) { delay(20); if (K16 == LOW) { showType = 23 ; startShow(showType); } } // =========================================================================================== if (K17 == LOW && K17Old == HIGH) { delay(20); if (K17 == LOW) { showType = 24 ; startShow(showType); } } // =========================================================================================== if (K18 == LOW && K18Old == HIGH) { delay(20); if (K18 == LOW) { showType = 25 ; startShow(showType); } } // =========================================================================================== if (Rainbow == LOW && RainbowOld == HIGH) { delay(20); if (Rainbow == LOW) { showType = 26 ; startShow(showType); } } // =========================================================================================== offOld = off; R1Old = R1; R2Old = R2; R3Old = R3; R4Old = R4; R5Old = R5; R6Old = R6; R7Old = R7; K1Old = K1; K2Old = K2; K3Old = K3; K4Old = K4; K5Old = K5; K6Old = K6; K7Old = K7; K8Old = K8; K9Old = K9; K10Old = K10; K11Old = K11; K12Old = K12; K13Old = K13; K14Old = K14; K15Old = K15; K16Old = K16; K17Old = K17; K18Old = K18; RainbowOld = Rainbow; } void startShow(int i) { switch(i){ case 0: colorWipe(strip.Color(0, 0, 0), SPEED); // Black/off break; case 1: strip.setPixelColor(6 ,0 ,255 ,0 ), SPEED; // R1 strip.show(); break; case 2: strip.setPixelColor(5 ,0 ,255 ,0 ), SPEED; // R2 strip.show(); break; case 3: strip.setPixelColor(4 ,0 ,255 ,0 ), SPEED; // R3 strip.show(); break; case 4: strip.setPixelColor(3 ,0 ,255 ,0 ), SPEED; // R4 strip.show(); break; case 5: strip.setPixelColor(2 ,0 ,255 ,0 ), SPEED; // R5 strip.show(); break; case 6: strip.setPixelColor(1 ,0 ,255 ,0 ), SPEED; // R6 strip.show(); break; case 7: strip.setPixelColor(0 ,0 ,255 ,0 ), SPEED; // R7 strip.show(); break; case 8: strip.setPixelColor(7 ,0 ,255 ,0 ), SPEED; // K1 strip.show(); break; case 9: strip.setPixelColor(8 ,0 ,255 ,0 ), SPEED; // K2 strip.show(); break; case 10: strip.setPixelColor(9 ,0 ,255 ,0 ), SPEED; // K3 strip.show(); break; case 11: strip.setPixelColor(10 ,0 ,255 ,0 ), SPEED; // K4 strip.show(); break; case 12: strip.setPixelColor(11 ,0 ,255 ,0 ), SPEED; // K5 strip.show(); break; case 13: strip.setPixelColor(12 ,0 ,255 ,0 ), SPEED; // K6 strip.show(); break; case 14: strip.setPixelColor(13 ,0 ,255 ,0 ), SPEED; // K7 strip.show(); break; case 15: strip.setPixelColor(14 ,0 ,255 ,0 ), SPEED; // K8 strip.show(); break; case 16: strip.setPixelColor(15 ,0 ,255 ,0 ), SPEED; // K9 strip.show(); break; case 17: strip.setPixelColor(16 ,0 ,255 ,0 ), SPEED; // K10 strip.show(); break; case 18: strip.setPixelColor(17 ,0 ,255 ,0 ), SPEED; // K11 strip.show(); break; case 19: strip.setPixelColor(18 ,0 ,255 ,0 ), SPEED; // K12 strip.show(); break; case 20: strip.setPixelColor(19 ,0 ,255 ,0 ), SPEED; // K13 strip.show(); break; case 21: strip.setPixelColor(20 ,0 ,255 ,0 ), SPEED; // K14 strip.show(); break; case 22: strip.setPixelColor(21 ,0 ,255 ,0 ), SPEED; // K15 strip.show(); break; case 23: strip.setPixelColor(22 ,0 ,255 ,0 ), SPEED; // K16 strip.show(); break; case 24: strip.setPixelColor(23 ,0 ,255 ,0 ), SPEED; // K17 strip.show(); break; case 25: strip.setPixelColor(24 ,0 ,255 ,0 ), SPEED; // K18 strip.show(); break; case 26: rainbowCycle(25); break; } } //END OF USABLE CODE void colorWipe(uint32_t c, uint8_t wait) { for(uint16_t i=0; i<strip.numPixels(); i++) { strip.setPixelColor(i, c); strip.show(); delay(wait); } } void rainbowCycle(uint8_t wait) { uint16_t i, j; for(j=0; j<256*10; j++) { // 5 cycles of all colors on wheel for(i=0; i< strip.numPixels(); i++) { strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255)); } strip.show(); delay(wait); } } void theaterChase(uint32_t c, uint8_t wait) { for (int j=0; j<10; j++) { //do 10 cycles of chasing for (int q=0; q < 3; q++) { for (int i=0; i < strip.numPixels(); i=i+3) { strip.setPixelColor(i+q, c); //turn every third pixel on } strip.show(); delay(wait); for (int i=0; i < strip.numPixels(); i=i+3) { strip.setPixelColor(i+q, 0); //turn every third pixel off } } } } uint32_t Wheel(byte WheelPos) { WheelPos = 255 - WheelPos; if(WheelPos < 85) { return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3); } if(WheelPos < 170) { WheelPos -= 85; return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3); } WheelPos -= 170; return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0); }
run
|
edit
|
history
|
help
0
Check if a year is leap year or not
sort
user defined exception
Vector of pointer of P...
Thread-safe Interval Average Calculator
virtual members
Clang-IsBaseOf
C++ Operator Overloading
Access to temporary object
template specialization inheritance problem