Project description
Code
Christmas_Village.ino
arduino
1int LDRPin = A0; // Pin where the LDR is connected 2int LED_1 = 2; 3int LED_2 = 3; 4int LED_3 = 4; 5int LED_4 = 5; 6int LED_5 = 6; 7int LED_6 = 7; 8int LED_7 = A4; 9int RGB_1 = A1; 10int RGB_2 = A2; 11int RGB_3 = A3; 12int RGB_Value = 0; 13int ledState = false; 14 15void setup() { 16 Serial.begin(9600); 17 pinMode(LED_1, OUTPUT); 18 pinMode(LED_2, OUTPUT); 19 pinMode(LED_3, OUTPUT); 20 pinMode(LED_4, OUTPUT); 21 pinMode(LED_5, OUTPUT); 22 pinMode(LED_6, OUTPUT); 23 pinMode(LED_7, OUTPUT); 24 pinMode(RGB_1, OUTPUT); 25 pinMode(RGB_2, OUTPUT); 26 pinMode(RGB_3, OUTPUT); 27} 28 29void loop() { 30 RGB_LED_Flash(); // Constant flash 31 32 //int ldrStatus = analogRead(LDRPin); 33 //if (ldrStatus <= 100) { // If no light is detected then turn on the LEDs 34 LED_Flash(); 35 /*} else { // If Light is detected turn off all the LEDs 36 digitalWrite(LED_1, LOW); 37 digitalWrite(LED_2, LOW); 38 digitalWrite(LED_3, LOW); 39 digitalWrite(LED_4, LOW); 40 digitalWrite(LED_5, LOW); 41 digitalWrite(LED_6, LOW); 42 };*/ 43 44 delay(200); // Wait for 200ms 45} 46 47 48void RGB_LED_Flash(){ 49 switch (RGB_Value) { 50 case 0: 51 digitalWrite(RGB_1, HIGH);digitalWrite(RGB_2, LOW);digitalWrite(RGB_3, LOW); 52 break; 53 case 1: 54 digitalWrite(RGB_1, LOW);digitalWrite(RGB_2, HIGH);digitalWrite(RGB_3, LOW); 55 break; 56 case 2: 57 digitalWrite(RGB_1, LOW);digitalWrite(RGB_2, LOW);digitalWrite(RGB_3, HIGH); 58 RGB_Value=-1; 59 break; 60 } RGB_Value++; 61} 62 63 64void LED_Flash(){ 65 digitalWrite(LED_1, ledState);digitalWrite(LED_3, ledState);digitalWrite(LED_5, ledState); 66 digitalWrite(LED_2, !ledState);digitalWrite(LED_4, !ledState);digitalWrite(LED_6, !ledState); 67 ledState = ! ledState; // Invert the LED state 68 digitalWrite(LED_7, HIGH); 69} 70
Comments
Only logged in users can leave comments