dylanraymond
Published © CC BY

Traffic Advisor (arrow stick)

8 light, rear of vehicle traffic advisor controller, with 4 modes and 14 patterns.

IntermediateShowcase (no instructions)2,535
Traffic Advisor (arrow stick)

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
3 mm LED: Yellow
3 mm LED: Yellow
×8
3 mm LED: Green
3 mm LED: Green
×1
Pushbutton Switch, Momentary
Pushbutton Switch, Momentary
4 pin, small generaic push button
×6
Resistor 220 ohm
Resistor 220 ohm
×6
Hook Up Wire Kit, 22 AWG
Hook Up Wire Kit, 22 AWG
×1
Relay Shield for Particle Photon I²C 8-Channel SPDT 10-Amp
ControlEverything.com Relay Shield for Particle Photon I²C 8-Channel SPDT 10-Amp
×1
Adafruit NeoPixel Digital RGB LED Strip 144 LED, 1m White
Adafruit NeoPixel Digital RGB LED Strip 144 LED, 1m White
×1

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free
Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires
Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires

Story

Read more

Schematics

schematic

Code

Code

C/C++
.INO
#include <EEPROM.h>
int warning_button = A5;
int left_button = 2;
int center_button = 4;
int right_button = 3;
int off_button = A0;
int pattern_button = A2;
int statuslight = 13;
int LEDright[] = {5, 6, 7, 8, 9, 10, 11, 12};
int LEDleft[] = {12, 11, 10, 9, 8, 7, 6, 5};
int centerleft[] = {9, 10, 11, 12};
int centerright[] = {8, 7, 6, 5};
int light = 0;
int counter = 1;
int pattern_count = 0;
int warning_count = EEPROM.read(0);
long lasttimer = 0;
static long timer = 200;
static long timer2 = 300;
static long switch_timer = 4000;
#define LEFTside 0x0
#define RIGHTside 0x1
byte whichLED = LEFTside;
byte LEFT_state = LOW;
byte RIGHT_state = LOW;
unsigned long switchDelay = 1000;
unsigned long switchDelay2 = 500;
unsigned long strobeDelay = 75;
unsigned long strobeWait = strobeDelay;
unsigned long waitUntilSwitch = switchDelay;
unsigned long sequenceStartTime;
//----------------------------------------------------------------------------
void setup() {
  Serial.begin(9600);
  for (int i = 0; i < 8; i++) {
    pinMode(LEDright[i], OUTPUT);
  }
  pinMode(statuslight, OUTPUT);
  pinMode(warning_button, INPUT_PULLUP);
  pinMode(left_button, INPUT_PULLUP);
  pinMode(center_button, INPUT_PULLUP);
  pinMode(right_button, INPUT_PULLUP);
  pinMode(off_button, INPUT_PULLUP);
  pinMode(pattern_button, INPUT_PULLUP);
  pinMode(12, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(5, OUTPUT);
}
//------------------------------------------------------------------------
void loop() {
  digitalWrite(13, HIGH);
  delayMicroseconds(10); // Approximately 10% duty cycle @ 1KHz
  digitalWrite(13, LOW);
  delayMicroseconds(1000 - 10);
  if (digitalRead(pattern_button) == HIGH)
  {
    delay(500);
    warning_count++;
    if (warning_count > 10) {
      warning_count = 1;
    }
  }
  if (digitalRead(warning_button) == HIGH)
  {
    delay(50);
    pattern_count = 1; 
  }
  if (digitalRead(left_button) == HIGH)
  {
    delay(50);
    pattern_count = 2;
  }
  if (digitalRead(center_button) == HIGH)
  {
    delay(50);
    pattern_count = 3;
  }
  if (digitalRead(right_button) == HIGH)
  {
    delay(50);
    pattern_count = 4;
  }
  if (digitalRead(off_button) == HIGH)
  {
    delay(50);
    pattern_count = 0;
    EEPROM.update(0,warning_count);
  }
  switch (pattern_count) {
    case 0:
      pattern_off();
      break;
    case 1:
      traffic_left();
      break;
    case 2:
      traffic_center();
      break;
    case 3:
      traffic_right();
      break;
    case 4:
      traffic_warning();
      break;
  }
}
void pattern_off() {
  for (int i = 0; i <= 7; i++) {
    digitalWrite(LEDright[i], LOW);
  }
}
void traffic_left() {
  unsigned long currenttimer = millis();
  if (currenttimer - lasttimer >= timer) {
    lasttimer = currenttimer;
    for (int i = 0; i <= 7; i++) {
      digitalWrite(LEDright[i], LOW);
    }
    digitalWrite(LEDleft[light], LOW);
    light = light + counter;
    if (light > 7) {
      light = 0;
      counter = 1;
    }
    digitalWrite(LEDleft[light], HIGH);
  }
}
void traffic_center() {
  unsigned long currenttimer = millis();
  if (currenttimer - lasttimer >= timer2) {
    lasttimer = currenttimer;
    for (int i = 0; i <= 7; i++) {
      digitalWrite(LEDright[i], LOW);
    }
    digitalWrite(centerright[light], LOW);
    digitalWrite(centerleft[light], LOW);
    light = light + counter;
    if (light > 3) {
      light = 0;
      counter = 1;
    }
    digitalWrite(centerright[light], HIGH);
    digitalWrite(centerleft[light], HIGH);
  }
}
void traffic_right() {
  unsigned long currenttimer = millis();
  if (currenttimer - lasttimer >= timer) {
    lasttimer = currenttimer;
    for (int i = 0; i <= 7; i++) {
      digitalWrite(LEDright[i], LOW);
    }
    digitalWrite(LEDright[light], LOW);
    light = light + counter;
    if (light > 7) {
      light = 0;
      counter = 1;
    }
    digitalWrite(LEDright[light], HIGH);
  }
}
void traffic_warning() {
  switch (warning_count) {
    case 1:
      even_odd_flash();
      break;
    case 2:
      half_half();
      break;
    case 3:
      half_half_flash();
      break;
    case 4:
      two_by_two();
      break;
    case 5:
      two_by_two_parallel();
      break;
    case 6:
      out_flash();
      break;
    case 7:
      one_center();
      break;
    case 8:
      outboard();
      break;
    case 9:
      inboard();
      break;
    case 10:
      even_odd();
      break;
  }
}
void even_odd_flash() {
  for (int i = 0; i <= 7; i++) {
    digitalWrite(LEDright[i], LOW);
  }
  digitalWrite(12, LEFT_state);
  digitalWrite(11, RIGHT_state);
  digitalWrite(10, LEFT_state);
  digitalWrite(9, RIGHT_state);
  digitalWrite(8, LEFT_state);
  digitalWrite(7, RIGHT_state);
  digitalWrite(6, LEFT_state);
  digitalWrite(5, RIGHT_state);
  if ((long)(millis() - waitUntilSwitch) >= 0) {
    LEFT_state = LOW;
    RIGHT_state = LOW;
    whichLED = !whichLED;
    waitUntilSwitch += switchDelay;
  }
  if ((long)(millis() - strobeWait) >= 0) {
    if (whichLED == LEFTside)
      LEFT_state = !LEFT_state;
    if (whichLED == RIGHTside)
      RIGHT_state = !RIGHT_state;
    strobeWait += strobeDelay;
  }
}
void half_half_flash() {
  for (int i = 0; i <= 7; i++) {
    digitalWrite(LEDright[i], LOW);
  }
  digitalWrite(12, LEFT_state);
  digitalWrite(11, LEFT_state);
  digitalWrite(10, LEFT_state);
  digitalWrite(9, LEFT_state);
  digitalWrite(8, RIGHT_state);
  digitalWrite(7, RIGHT_state);
  digitalWrite(6, RIGHT_state);
  digitalWrite(5, RIGHT_state);
  if ((long)(millis() - waitUntilSwitch) >= 0) {
    LEFT_state = LOW;
    RIGHT_state = LOW;
    whichLED = !whichLED;
    waitUntilSwitch += switchDelay2;
  }
  if ((long)(millis() - strobeWait) >= 0) {
    if (whichLED == LEFTside)
      LEFT_state = !LEFT_state;
    if (whichLED == RIGHTside)
      RIGHT_state = !RIGHT_state;
    strobeWait += strobeDelay;
  }
}
void half_half() {
  for (int i = 0; i <= 7; i++) {
    digitalWrite(LEDright[i], LOW);
  }
  long time = millis() - sequenceStartTime;
  if (time < 250)
  {
    digitalWrite(12, HIGH);
    digitalWrite(11, HIGH);
    digitalWrite(10, HIGH);
    digitalWrite(9, HIGH);
    digitalWrite(8, LOW);
    digitalWrite(7, LOW);
    digitalWrite(6, LOW);
    digitalWrite(5, LOW);
  }
  else if (time < 500)
  {
    digitalWrite(12, LOW);
    digitalWrite(11, LOW);
    digitalWrite(10, LOW);
    digitalWrite(9, LOW);
    digitalWrite(8, HIGH);
    digitalWrite(7, HIGH);
    digitalWrite(6, HIGH);
    digitalWrite(5, HIGH);
  }
  else sequenceStartTime = millis();
}
void out_flash() {
  for (int i = 0; i <= 7; i++) {
    digitalWrite(LEDright[i], LOW);
  }
  long time = millis() - sequenceStartTime;
  if (time < 150)
  {
    digitalWrite(12, HIGH);
    digitalWrite(11, HIGH);
    digitalWrite(10, LOW);
    digitalWrite(9, LOW);
    digitalWrite(8, LOW);
    digitalWrite(7, LOW);
    digitalWrite(6, HIGH);
    digitalWrite(5, HIGH);
  }
  else if (time < 300)
  {
    digitalWrite(12, LOW);
    digitalWrite(11, HIGH);
    digitalWrite(10, HIGH);
    digitalWrite(9, LOW);
    digitalWrite(8, LOW);
    digitalWrite(7, HIGH);
    digitalWrite(6, HIGH);
    digitalWrite(5, LOW);
  }
  else sequenceStartTime = millis();
}
void two_by_two() {
  for (int i = 0; i <= 7; i++) {
    digitalWrite(LEDright[i], LOW);
  }
  long time = millis() - sequenceStartTime;
  if (time < 150)
  {
    digitalWrite(12, HIGH);
    digitalWrite(11, HIGH);
    digitalWrite(10, LOW);
    digitalWrite(9, LOW);
    digitalWrite(8, LOW);
    digitalWrite(7, LOW);
    digitalWrite(6, HIGH);
    digitalWrite(5, HIGH);
  }
  else if (time < 300)
  {
    digitalWrite(12, LOW);
    digitalWrite(11, LOW);
    digitalWrite(10, HIGH);
    digitalWrite(9, HIGH);
    digitalWrite(8, HIGH);
    digitalWrite(7, HIGH);
    digitalWrite(6, LOW);
    digitalWrite(5, LOW);
  }
  else sequenceStartTime = millis();
}
void two_by_two_parallel() {
  for (int i = 0; i <= 7; i++) {
    digitalWrite(LEDright[i], LOW);
  }
  long time = millis() - sequenceStartTime;
  if (time < 150)
  {
    digitalWrite(12, HIGH);
    digitalWrite(11, HIGH);
    digitalWrite(10, LOW);
    digitalWrite(9, LOW);
    digitalWrite(8, HIGH);
    digitalWrite(7, HIGH);
    digitalWrite(6, LOW);
    digitalWrite(5, LOW);
  }
  else if (time < 300)
  {
    digitalWrite(12, LOW);
    digitalWrite(11, LOW);
    digitalWrite(10, HIGH);
    digitalWrite(9, HIGH);
    digitalWrite(8, LOW);
    digitalWrite(7, LOW);
    digitalWrite(6, HIGH);
    digitalWrite(5, HIGH);
  }
  else sequenceStartTime = millis();
}
void one_center() {
  for (int i = 0; i <= 7; i++) {
    digitalWrite(LEDright[i], LOW);
  }
  long time = millis() - sequenceStartTime;
  if (time < 500)
  {
    digitalWrite(12, HIGH);
    digitalWrite(11, HIGH);
    digitalWrite(10, HIGH);
    digitalWrite(9, LOW);
    digitalWrite(8, HIGH);
    digitalWrite(7, LOW);
    digitalWrite(6, LOW);
    digitalWrite(5, LOW);
  }
  else if (time < 1000)
  {
    digitalWrite(12, LOW);
    digitalWrite(11, LOW);
    digitalWrite(10, LOW);
    digitalWrite(9, HIGH);
    digitalWrite(8, LOW);
    digitalWrite(7, HIGH);
    digitalWrite(6, HIGH);
    digitalWrite(5, HIGH);
  }
  else sequenceStartTime = millis();
}
void outboard() {
  for (int i = 0; i <= 7; i++) {
    digitalWrite(LEDright[i], LOW);
  }
  long time = millis() - sequenceStartTime;
  if (time < 200)
  {
    digitalWrite(12, HIGH);
    digitalWrite(11, HIGH);
    digitalWrite(6, LOW);
    digitalWrite(5, LOW);
  }
  else if (time < 400)
  {
    digitalWrite(12, LOW);
    digitalWrite(11, LOW);
    digitalWrite(6, HIGH);
    digitalWrite(5, HIGH);
  }
  else sequenceStartTime = millis();
}
void inboard() {
  for (int i = 0; i <= 7; i++) {
    digitalWrite(LEDright[i], LOW);
  }
  long time = millis() - sequenceStartTime;
  if (time < 200)
  {
    digitalWrite(11, HIGH);
    digitalWrite(10, HIGH);
    digitalWrite(9, LOW);
    digitalWrite(8, LOW);
    digitalWrite(7, HIGH);
    digitalWrite(6, HIGH);
  }
  else if (time < 400)
  {
    digitalWrite(11, LOW);
    digitalWrite(10, LOW);
    digitalWrite(9, HIGH);
    digitalWrite(8, HIGH);
    digitalWrite(7, LOW);
    digitalWrite(6, LOW);
  }
  else sequenceStartTime = millis();
}
void even_odd() {
  for (int i = 0; i <= 7; i++) {
    digitalWrite(LEDright[i], LOW);
  }
  long time = millis() - sequenceStartTime;
  if (time < 300)
  {
    digitalWrite(12, HIGH);
    digitalWrite(11, LOW);
    digitalWrite(10, HIGH);
    digitalWrite(9, LOW);
    digitalWrite(8, HIGH);
    digitalWrite(7, LOW);
    digitalWrite(6, HIGH);
    digitalWrite(5, LOW);
  }
  else if (time < 600)
  {
    digitalWrite(12, LOW);
    digitalWrite(11, HIGH);
    digitalWrite(10, LOW);
    digitalWrite(9, HIGH);
    digitalWrite(8, LOW);
    digitalWrite(7, HIGH);
    digitalWrite(6, LOW);
    digitalWrite(5, HIGH);
  }
  else sequenceStartTime = millis();
}

Credits

dylanraymond

dylanraymond

1 project • 3 followers

Comments