+++ /dev/null
-/*
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as
- published by the Free Software Foundation, either version 3 of
- the License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/*
- * traffic lights
- */
-
-int red0 = 12;
-int yellow0 = 11;
-int green0 = 10;
-
-int red1 = 7;
-int yellow1 = 6;
-int green1 = 5;
-
-void setup() {
- pinMode(red0, OUTPUT);
- pinMode(red1, OUTPUT);
- pinMode(yellow0, OUTPUT);
- pinMode(yellow1, OUTPUT);
- pinMode(green0, OUTPUT);
- pinMode(green1, OUTPUT);
-}
-
-/*
- on(pinNumber);
- turn on pin 'pinNumber'.
- digitalWrite(pinNumber, HIGH); turns the voltage on for that pin.
- */
-void on(int pinToTurnOn) {
- digitalWrite(pinToTurnOn, HIGH);
-}
-
-/*
- off(pinNumber);
- turn off pin 'pinNumber'.
- digitalWrite(pinNumber, LOW); turns the voltage off for that pin.
-*/
-void off(int pinToTurnOff) {
- digitalWrite(pinToTurnOff, LOW);
-}
-
-void onsOffs(int* pinsToTurnOn, int numberOfPinsToTurnOn,
- int* pinsToTurnOff, int numberOfPinsToTurnOff){
- // generic index used for arrays of pins to turn on or off
- int index;
- // turn off pins in pinsToTurnOff
- for(index = 0; index < numberOfPinsToTurnOff; index++) {
- off(pinsToTurnOff[index]);
- }
- // turn on pins in pinsToTurnOn
- for(index = 0; index < numberOfPinsToTurnOn; index++) {
- on(pinsToTurnOn[index]);
- }
-}
-
-void loop() {
- int redWait = 300;
- int yellowWait = 800;
- int greenWait = 1600;
-
- onsOffs((int[]){red0, green1}, 2,
- (int[]){yellow0, green0, red1, yellow1}, 4);
- delay(greenWait);
-
- onsOffs((int[]){red0, yellow1}, 2,
- (int[]){yellow0, green0, red1, green1}, 4);
- delay(yellowWait);
-
- onsOffs((int[]){red0, red1}, 2,
- (int[]){yellow0, green0, yellow1, green1}, 4);
- delay(redWait);
-
- onsOffs((int[]){green0, red1}, 2,
- (int[]){red0, yellow0, yellow1, green1}, 4);
- delay(greenWait);
-
- onsOffs((int[]){yellow0, red1}, 2,
- (int[]){red0, green0, yellow1, green1}, 4);
- delay(yellowWait);
-
- onsOffs((int[]){red0, red1}, 2,
- (int[]){yellow0, green0, yellow1, green1}, 4);
- delay(redWait);
-}