So basically where I'm at now is I am looking for someone to write a code for my project which I am using my arduino uno to program onto a attiny84 chip. I have a traffic light and I want to get my program to do some specific things, however I have spent over 3 weeks trying to write this code with no luck and don't have anymore free time to spend on this project (per wife's orders).
I want the code to control a RED YELLOW and GREEN light to cycle upon power up. Red to come up with a random time between 16 and 55 seconds, yellow to be set at a fixed 4 seconds, and green to come up with a random time between 10 and 48 seconds. I want every cycle to pull up new random times on the red and green while always keeping yellow at a fixed 4 seconds. I want the cycle to start with the green time when first powered up or reset.
Also, I want the program to have a input for one momentary push button input that will send the program from normal cycle (during any part of the cycle) to flashing the yellow light at a rate of 533 milliseconds upon the first push, send the program to flashing the red light at a rate of 533 milliseconds upon the second push, and than return to normal cycle upon the third push and so on.
This push button will read low under normal and when pushed will read high.
I am really good at the electronics side of this and have already designed the pcb board and received the components but I have not got enough experience with programing to write the actual code which is where I need someones help.
My PCBs pins have already been assigned for the attiny84 as follows:
here is a sketch to try. I'm sure there are better or easier ways but I'm some what new to this but it was fun working this out. I got it working on my arduino UNO.
int button = 5;
int red = 11;
int yellow = 12;
int green = 13;
int mode = 0;
int buttonPushed;
int buttonState;
boolean released = true;
boolean pushed = false;
int currentMode;
// time sets the flash rate of the yellow cycle and red cycle. 1 second = 15
long time = 8;
void setup()
{
pinMode(button, INPUT);
pinMode(red, OUTPUT);
pinMode(yellow, OUTPUT);
pinMode(green, OUTPUT);
digitalWrite(red, LOW);
digitalWrite(yellow,LOW);
digitalWrite(green, LOW);
digitalWrite(button, LOW);
}
void loop()
{
// normal mode
if(mode == 0)
{
currentMode = 0;
digitalWrite(red, LOW);
digitalWrite(yellow, LOW);
digitalWrite(green, HIGH);
delaying(random(150,720));
digitalWrite(green, LOW);
digitalWrite(red, LOW);
digitalWrite(yellow, HIGH);
delaying(60);
digitalWrite(green, LOW);
digitalWrite(yellow, LOW);
digitalWrite(red, HIGH);
delaying(random(240,825));
}
// yellow mode
if(mode == 1)
{
currentMode = 1;
digitalWrite(green, LOW);
digitalWrite(red, LOW);
digitalWrite(yellow, HIGH);
delaying(time);
digitalWrite(yellow, LOW);
delaying(time);
}
// red mode
if(mode == 2)
{
currentMode = 2;
digitalWrite(green, LOW);
digitalWrite(yellow, LOW);
digitalWrite(red, HIGH);
delaying(time);
digitalWrite(red, LOW);
delaying(time);
}
}
// ******************************end loop*****************
void buttonCheck() //checks to see if the button has been pushed. Modes will change on release of button.
{
buttonPushed = digitalRead(button);
delay(50);
buttonState = buttonPushed;
if(buttonState == 1 && released == true)
{
pushed = true;
released = false;
}
if(buttonState == 0 && released == false)
{
released = true;
}
if(pushed == true && released == true)
{
if(mode == 2)
{
mode = 0;
}
else
{
mode ++;
}
pushed = false;
}
}
void delaying(long t) // Delays 1 millisecond and checks for button press. continues to delay as long as button is not pressed.
{
for(int i = 0; i < t; i++)
{
buttonCheck();
if(currentMode != mode)
{
break;
}
delay(1);
}
}