Apps and platforms
Arduino IDE
Project description
Code
LED and Switch Array
arduino
1//Control LED bar graph function based on input from switch array 2//Last modified April 2019 3 4int LED0 = 0; 5int LED1 = 1; 6int LED2 = 2; 7int LED3 = 3; 8int LED4 = 4; 9int LED5 = 5; 10int LED6 = 6; 11int LED7 = 7; 12int LED8 = 8; 13 14int switch1 = 9; 15int switch2 = 10; 16int switch3 = 11; 17int switch4 = 12; 18int switch5 = 13; 19 20int s1status = 0; 21int s2status = 0; 22int s3status = 0; 23int s4status = 0; 24int s5status = 0; 25 26void setup() { 27 //set pins 0-8 as output 28 pinMode(LED0, OUTPUT); 29 pinMode(LED1, OUTPUT); 30 pinMode(LED2, OUTPUT); 31 pinMode(LED3, OUTPUT); 32 pinMode(LED4, OUTPUT); 33 pinMode(LED5, OUTPUT); 34 pinMode(LED6, OUTPUT); 35 pinMode(LED7, OUTPUT); 36 pinMode(LED8, OUTPUT); 37 38 //set pins 9-14 as input 39 pinMode(switch1, INPUT); 40 pinMode(switch2, INPUT); 41 pinMode(switch3, INPUT); 42 pinMode(switch4, INPUT); 43 pinMode(switch5, INPUT); 44 45} 46 47void loop() { 48 //check inputs from switches 49 s1status = digitalRead(switch1); 50 s2status = digitalRead(switch2); 51 s3status = digitalRead(switch3); 52 s4status = digitalRead(switch4); 53 s5status = digitalRead(switch5); 54 55 if(s1status == 1){ 56 //perform LED function 1 -- forward light 57 58 digitalWrite(LED0, HIGH); 59 delay(200); 60 digitalWrite(LED0, LOW); 61 digitalWrite(LED1, HIGH); 62 delay(200); 63 digitalWrite(LED1, LOW); 64 digitalWrite(LED2, HIGH); 65 delay(200); 66 digitalWrite(LED2, LOW); 67 digitalWrite(LED3, HIGH); 68 delay(200); 69 digitalWrite(LED3, LOW); 70 digitalWrite(LED4, HIGH); 71 delay(200); 72 digitalWrite(LED4, LOW); 73 digitalWrite(LED5, HIGH); 74 delay(200); 75 digitalWrite(LED5, LOW); 76 digitalWrite(LED6, HIGH); 77 delay(200); 78 digitalWrite(LED6, LOW); 79 digitalWrite(LED7, HIGH); 80 delay(200); 81 digitalWrite(LED7, LOW); 82 digitalWrite(LED8, HIGH); 83 delay(200); 84 digitalWrite(LED8, LOW); 85 } 86 87 else if (s2status == 1){ 88 //perform LED function 2 -- group toggle 89 90 //Turn ON LEDs 0-3, turn OFF 4-7 91 digitalWrite(LED4, LOW); 92 digitalWrite(LED5, LOW); 93 digitalWrite(LED6, LOW); 94 digitalWrite(LED7, LOW); 95 digitalWrite(LED0, HIGH); 96 digitalWrite(LED1, HIGH); 97 digitalWrite(LED2, HIGH); 98 digitalWrite(LED3, HIGH); 99 delay(200); 100 101 //Turn OFF LEDs 0-3, turn ON 4-7 102 digitalWrite(LED0, LOW); 103 digitalWrite(LED1, LOW); 104 digitalWrite(LED2, LOW); 105 digitalWrite(LED3, LOW); 106 digitalWrite(LED4, HIGH); 107 digitalWrite(LED5, HIGH); 108 digitalWrite(LED6, HIGH); 109 digitalWrite(LED7, HIGH); 110 delay(200); 111 } 112 113 else if (s3status == 1){ 114 //perform LED function 3 -- backward light 115 116 digitalWrite(LED8, HIGH); 117 delay(200); 118 digitalWrite(LED8, LOW); 119 digitalWrite(LED7, HIGH); 120 delay(200); 121 digitalWrite(LED7, LOW); 122 digitalWrite(LED6, HIGH); 123 delay(200); 124 digitalWrite(LED6, LOW); 125 digitalWrite(LED5, HIGH); 126 delay(200); 127 digitalWrite(LED5, LOW); 128 digitalWrite(LED4, HIGH); 129 delay(200); 130 digitalWrite(LED4, LOW); 131 digitalWrite(LED3, HIGH); 132 delay(200); 133 digitalWrite(LED3, LOW); 134 digitalWrite(LED2, HIGH); 135 delay(200); 136 digitalWrite(LED2, LOW); 137 digitalWrite(LED1, HIGH); 138 delay(200); 139 digitalWrite(LED1, LOW); 140 digitalWrite(LED0, HIGH); 141 delay(200); 142 digitalWrite(LED0, LOW); 143 } 144 145 else if (s4status == 1){ 146 //perform LED function 4 - forward and backward light 147 148 //foward 149 digitalWrite(LED0, HIGH); 150 delay(200); 151 digitalWrite(LED0, LOW); 152 digitalWrite(LED1, HIGH); 153 delay(200); 154 digitalWrite(LED1, LOW); 155 digitalWrite(LED2, HIGH); 156 delay(200); 157 digitalWrite(LED2, LOW); 158 digitalWrite(LED3, HIGH); 159 delay(200); 160 digitalWrite(LED3, LOW); 161 digitalWrite(LED4, HIGH); 162 delay(200); 163 digitalWrite(LED4, LOW); 164 digitalWrite(LED5, HIGH); 165 delay(200); 166 digitalWrite(LED5, LOW); 167 digitalWrite(LED6, HIGH); 168 delay(200); 169 digitalWrite(LED6, LOW); 170 digitalWrite(LED7, HIGH); 171 delay(200); 172 digitalWrite(LED7, LOW); 173 digitalWrite(LED8, HIGH); 174 delay(200); 175 digitalWrite(LED8, LOW); 176 177 //backward 178 digitalWrite(LED8, HIGH); 179 delay(200); 180 digitalWrite(LED8, LOW); 181 digitalWrite(LED7, HIGH); 182 delay(200); 183 digitalWrite(LED7, LOW); 184 digitalWrite(LED6, HIGH); 185 delay(200); 186 digitalWrite(LED6, LOW); 187 digitalWrite(LED5, HIGH); 188 delay(200); 189 digitalWrite(LED5, LOW); 190 digitalWrite(LED4, HIGH); 191 delay(200); 192 digitalWrite(LED4, LOW); 193 digitalWrite(LED3, HIGH); 194 delay(200); 195 digitalWrite(LED3, LOW); 196 digitalWrite(LED2, HIGH); 197 delay(200); 198 digitalWrite(LED2, LOW); 199 digitalWrite(LED1, HIGH); 200 delay(200); 201 digitalWrite(LED1, LOW); 202 digitalWrite(LED0, HIGH); 203 delay(200); 204 digitalWrite(LED0, LOW); 205 } 206 207 else if (s5status == 1){ 208 //perform LED function 5 -- Inward 209 210 digitalWrite(LED0, HIGH); 211 digitalWrite(LED7, HIGH); 212 delay(200); 213 digitalWrite(LED0, LOW); 214 digitalWrite(LED7, LOW); 215 digitalWrite(LED1, HIGH); 216 digitalWrite(LED6, HIGH); 217 delay(200); 218 digitalWrite(LED1, LOW); 219 digitalWrite(LED6, LOW); 220 digitalWrite(LED2, HIGH); 221 digitalWrite(LED5, HIGH); 222 delay(200); 223 digitalWrite(LED2, LOW); 224 digitalWrite(LED5, LOW); 225 digitalWrite(LED3, HIGH); 226 digitalWrite(LED4, HIGH); 227 delay(200); 228 digitalWrite(LED3, LOW); 229 digitalWrite(LED4, LOW); 230 delay(200); 231 232 } 233 234 else{ 235 //perform default LED function if no switch is ON 236 digitalWrite(LED0, LOW); 237 digitalWrite(LED1, LOW); 238 digitalWrite(LED2, LOW); 239 digitalWrite(LED3, LOW); 240 digitalWrite(LED4, LOW); 241 digitalWrite(LED5, LOW); 242 digitalWrite(LED6, LOW); 243 digitalWrite(LED7, LOW); 244 } 245 246}
LED and Switch Array
arduino
1//Control LED bar graph function based on input from switch array 2//Last modified April 2019 3 4int LED0 = 0; 5int LED1 = 1; 6int LED2 = 2; 7int LED3 = 3; 8int LED4 = 4; 9int LED5 = 5; 10int LED6 = 6; 11int LED7 = 7; 12int LED8 = 8; 13 14int switch1 = 9; 15int switch2 = 10; 16int switch3 = 11; 17int switch4 = 12; 18int switch5 = 13; 19 20int s1status = 0; 21int s2status = 0; 22int s3status = 0; 23int s4status = 0; 24int s5status = 0; 25 26void setup() { 27 //set pins 0-8 as output 28 pinMode(LED0, OUTPUT); 29 pinMode(LED1, OUTPUT); 30 pinMode(LED2, OUTPUT); 31 pinMode(LED3, OUTPUT); 32 pinMode(LED4, OUTPUT); 33 pinMode(LED5, OUTPUT); 34 pinMode(LED6, OUTPUT); 35 pinMode(LED7, OUTPUT); 36 pinMode(LED8, OUTPUT); 37 38 //set pins 9-14 as input 39 pinMode(switch1, INPUT); 40 pinMode(switch2, INPUT); 41 pinMode(switch3, INPUT); 42 pinMode(switch4, INPUT); 43 pinMode(switch5, INPUT); 44 45} 46 47void loop() { 48 //check inputs from switches 49 s1status = digitalRead(switch1); 50 s2status = digitalRead(switch2); 51 s3status = digitalRead(switch3); 52 s4status = digitalRead(switch4); 53 s5status = digitalRead(switch5); 54 55 if(s1status == 1){ 56 //perform LED function 1 -- forward light 57 58 digitalWrite(LED0, HIGH); 59 delay(200); 60 digitalWrite(LED0, LOW); 61 digitalWrite(LED1, HIGH); 62 delay(200); 63 digitalWrite(LED1, LOW); 64 digitalWrite(LED2, HIGH); 65 delay(200); 66 digitalWrite(LED2, LOW); 67 digitalWrite(LED3, HIGH); 68 delay(200); 69 digitalWrite(LED3, LOW); 70 digitalWrite(LED4, HIGH); 71 delay(200); 72 digitalWrite(LED4, LOW); 73 digitalWrite(LED5, HIGH); 74 delay(200); 75 digitalWrite(LED5, LOW); 76 digitalWrite(LED6, HIGH); 77 delay(200); 78 digitalWrite(LED6, LOW); 79 digitalWrite(LED7, HIGH); 80 delay(200); 81 digitalWrite(LED7, LOW); 82 digitalWrite(LED8, HIGH); 83 delay(200); 84 digitalWrite(LED8, LOW); 85 } 86 87 else if (s2status == 1){ 88 //perform LED function 2 -- group toggle 89 90 //Turn ON LEDs 0-3, turn OFF 4-7 91 digitalWrite(LED4, LOW); 92 digitalWrite(LED5, LOW); 93 digitalWrite(LED6, LOW); 94 digitalWrite(LED7, LOW); 95 digitalWrite(LED0, HIGH); 96 digitalWrite(LED1, HIGH); 97 digitalWrite(LED2, HIGH); 98 digitalWrite(LED3, HIGH); 99 delay(200); 100 101 //Turn OFF LEDs 0-3, turn ON 4-7 102 digitalWrite(LED0, LOW); 103 digitalWrite(LED1, LOW); 104 digitalWrite(LED2, LOW); 105 digitalWrite(LED3, LOW); 106 digitalWrite(LED4, HIGH); 107 digitalWrite(LED5, HIGH); 108 digitalWrite(LED6, HIGH); 109 digitalWrite(LED7, HIGH); 110 delay(200); 111 } 112 113 else if (s3status == 1){ 114 //perform LED function 3 -- backward light 115 116 digitalWrite(LED8, HIGH); 117 delay(200); 118 digitalWrite(LED8, LOW); 119 digitalWrite(LED7, HIGH); 120 delay(200); 121 digitalWrite(LED7, LOW); 122 digitalWrite(LED6, HIGH); 123 delay(200); 124 digitalWrite(LED6, LOW); 125 digitalWrite(LED5, HIGH); 126 delay(200); 127 digitalWrite(LED5, LOW); 128 digitalWrite(LED4, HIGH); 129 delay(200); 130 digitalWrite(LED4, LOW); 131 digitalWrite(LED3, HIGH); 132 delay(200); 133 digitalWrite(LED3, LOW); 134 digitalWrite(LED2, HIGH); 135 delay(200); 136 digitalWrite(LED2, LOW); 137 digitalWrite(LED1, HIGH); 138 delay(200); 139 digitalWrite(LED1, LOW); 140 digitalWrite(LED0, HIGH); 141 delay(200); 142 digitalWrite(LED0, LOW); 143 } 144 145 else if (s4status == 1){ 146 //perform LED function 4 - forward and backward light 147 148 //foward 149 digitalWrite(LED0, HIGH); 150 delay(200); 151 digitalWrite(LED0, LOW); 152 digitalWrite(LED1, HIGH); 153 delay(200); 154 digitalWrite(LED1, LOW); 155 digitalWrite(LED2, HIGH); 156 delay(200); 157 digitalWrite(LED2, LOW); 158 digitalWrite(LED3, HIGH); 159 delay(200); 160 digitalWrite(LED3, LOW); 161 digitalWrite(LED4, HIGH); 162 delay(200); 163 digitalWrite(LED4, LOW); 164 digitalWrite(LED5, HIGH); 165 delay(200); 166 digitalWrite(LED5, LOW); 167 digitalWrite(LED6, HIGH); 168 delay(200); 169 digitalWrite(LED6, LOW); 170 digitalWrite(LED7, HIGH); 171 delay(200); 172 digitalWrite(LED7, LOW); 173 digitalWrite(LED8, HIGH); 174 delay(200); 175 digitalWrite(LED8, LOW); 176 177 //backward 178 digitalWrite(LED8, HIGH); 179 delay(200); 180 digitalWrite(LED8, LOW); 181 digitalWrite(LED7, HIGH); 182 delay(200); 183 digitalWrite(LED7, LOW); 184 digitalWrite(LED6, HIGH); 185 delay(200); 186 digitalWrite(LED6, LOW); 187 digitalWrite(LED5, HIGH); 188 delay(200); 189 digitalWrite(LED5, LOW); 190 digitalWrite(LED4, HIGH); 191 delay(200); 192 digitalWrite(LED4, LOW); 193 digitalWrite(LED3, HIGH); 194 delay(200); 195 digitalWrite(LED3, LOW); 196 digitalWrite(LED2, HIGH); 197 delay(200); 198 digitalWrite(LED2, LOW); 199 digitalWrite(LED1, HIGH); 200 delay(200); 201 digitalWrite(LED1, LOW); 202 digitalWrite(LED0, HIGH); 203 delay(200); 204 digitalWrite(LED0, LOW); 205 } 206 207 else if (s5status == 1){ 208 //perform LED function 5 -- Inward 209 210 digitalWrite(LED0, HIGH); 211 digitalWrite(LED7, HIGH); 212 delay(200); 213 digitalWrite(LED0, LOW); 214 digitalWrite(LED7, LOW); 215 digitalWrite(LED1, HIGH); 216 digitalWrite(LED6, HIGH); 217 delay(200); 218 digitalWrite(LED1, LOW); 219 digitalWrite(LED6, LOW); 220 digitalWrite(LED2, HIGH); 221 digitalWrite(LED5, HIGH); 222 delay(200); 223 digitalWrite(LED2, LOW); 224 digitalWrite(LED5, LOW); 225 digitalWrite(LED3, HIGH); 226 digitalWrite(LED4, HIGH); 227 delay(200); 228 digitalWrite(LED3, LOW); 229 digitalWrite(LED4, LOW); 230 delay(200); 231 232 } 233 234 else{ 235 //perform default LED function if no switch is ON 236 digitalWrite(LED0, LOW); 237 digitalWrite(LED1, LOW); 238 digitalWrite(LED2, LOW); 239 digitalWrite(LED3, LOW); 240 digitalWrite(LED4, LOW); 241 digitalWrite(LED5, LOW); 242 digitalWrite(LED6, LOW); 243 digitalWrite(LED7, LOW); 244 } 245 246}
Downloadable files
Schematic
Schematic
Comments
Only logged in users can leave comments
ejshea
1 Followers
•17 Projects
1
0