2020-05-20 03:53:04 -04:00
|
|
|
// FILE: trafficLight.ino
|
2021-11-13 09:19:09 -05:00
|
|
|
// AUTHOR: Rob Tillaart
|
2020-05-20 03:53:04 -04:00
|
|
|
// PURPOSE: demo PinOutGroup library for Arduino
|
|
|
|
|
2021-11-13 09:19:09 -05:00
|
|
|
|
2020-05-20 03:53:04 -04:00
|
|
|
#include "PinOutGroup.h"
|
|
|
|
|
|
|
|
PinOutGroup trafficLight;
|
|
|
|
|
2021-11-13 09:19:09 -05:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
uint8_t lights[] = {11, 12, 13}; // connect 3 leds...
|
|
|
|
const int RED = 4;
|
|
|
|
const int YELLOW = 2;
|
|
|
|
const int GREEN = 1;
|
|
|
|
const int YELLOWRED = 6; // YELLOW | RED
|
2020-05-20 03:53:04 -04:00
|
|
|
|
|
|
|
int state = 0;
|
|
|
|
|
2021-11-13 09:19:09 -05:00
|
|
|
|
2020-05-20 03:53:04 -04:00
|
|
|
void setup()
|
|
|
|
{
|
|
|
|
Serial.begin(115200);
|
|
|
|
Serial.println(__FILE__);
|
|
|
|
Serial.print(F("PINOUTGROUP_LIB_VERSION: "));
|
|
|
|
Serial.println(PINOUTGROUP_LIB_VERSION);
|
|
|
|
Serial.println();
|
|
|
|
|
|
|
|
trafficLight.add(3, lights);
|
|
|
|
}
|
|
|
|
|
2021-11-13 09:19:09 -05:00
|
|
|
|
2020-05-20 03:53:04 -04:00
|
|
|
void loop()
|
|
|
|
{
|
|
|
|
switch (state)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
Serial.println("RED");
|
|
|
|
trafficLight.write(RED);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
Serial.println("YELLOWRED");
|
|
|
|
trafficLight.write(YELLOWRED);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
Serial.println("GREEN");
|
|
|
|
trafficLight.write(GREEN);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
Serial.println("YELLOW");
|
|
|
|
trafficLight.write(YELLOW);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
state++;
|
|
|
|
if (state == 4) state = 0;
|
|
|
|
delay(1000);
|
|
|
|
}
|
|
|
|
|
2021-11-13 09:19:09 -05:00
|
|
|
|
2020-05-20 03:53:04 -04:00
|
|
|
// -- END OF FILE --
|
2021-11-13 09:19:09 -05:00
|
|
|
|