Hey i doing a timer with a 555 chip and i need help with the code

The idea is that i use two switches. the left switch sets the diodes to the right. for every click a diod lights up and i equal to one blink from the 555. You can maximum set the time to 10 blinks (cyels). When it is 5 seconds left the right diod goes low and then the next etc. When the time is the same as the set blinks (cycles is 0) all diods schould be low and the green diod should light up (and the 555 stops). The right switch starts the 555 timer. (The pushbuttons act like switches). For some reason the diods dosent start to go low at the right time and the last diod never goes low aswell as the green dosent go high. I need some help with the code.

i have uploaded an picture of the circut and here is the code:
// C++ code
//

int button1 = 2;
int led = 13;
int statusNew;
int statusOld=1;
int ledstatus=0;
int timer=4;
int ledgl=8;
int ledbl=9;
int ledg=10;
int ledgr=11;
int ledbr=12;
int buttonup=5;
//t buttondw=6;
boolean oldbuttonstate=LOW;
boolean newbuttonstate=LOW;
boolean oldtimerstate=LOW;
boolean newtimerstate=LOW;
//int newtimerstate;
int timercount;
byte state=0;
byte c;
int ledgreen=6;

void setup()
{
pinMode(led, OUTPUT);
pinMode(button1, INPUT);
pinMode(timer, INPUT);
pinMode(buttonup, INPUT);
pinMode(ledgl,OUTPUT);
pinMode(ledbl,OUTPUT);
pinMode(ledg,OUTPUT);
pinMode(ledgr,OUTPUT);
pinMode(ledbr,OUTPUT);
pinMode(timer,INPUT);
pinMode(ledgreen,OUTPUT);
digitalWrite(ledgl,LOW);
digitalWrite(ledbl,LOW);
digitalWrite(ledg,LOW);
digitalWrite(ledgr,LOW);
digitalWrite(ledbr,LOW);
digitalWrite(ledgreen,LOW);
//Serial.begin(9600);
}
void loop(){
statusNew=digitalRead(button1);
newbuttonstate=digitalRead(buttonup);
newtimerstate=digitalRead(timer);
if (newbuttonstate != oldbuttonstate)
{
if(newbuttonstate==HIGH)
state++;
c++;
if (state>5){
state=5;
if(c>10);
c==10;
}
digitalWrite(ledgl,LOW);
digitalWrite(ledbl,LOW);
digitalWrite(ledg,LOW);
digitalWrite(ledgr,LOW);
digitalWrite(ledbr,LOW);

if(state==1){
  digitalWrite(ledgl,HIGH);}
if(state==2){
  digitalWrite(ledgl,HIGH);
  digitalWrite(ledbl,HIGH);}
if(state==3){
  digitalWrite(ledgl,HIGH);
  digitalWrite(ledbl,HIGH);
  digitalWrite(ledg,HIGH);}
if(state==4){
  digitalWrite(ledgl,HIGH);
  digitalWrite(ledbl,HIGH);
  digitalWrite(ledg,HIGH);
  digitalWrite(ledgr,HIGH);}
if(state==5){
  digitalWrite(ledgl,HIGH);
  digitalWrite(ledbl,HIGH);
  digitalWrite(ledg,HIGH);
  digitalWrite(ledgr,HIGH);
  digitalWrite(ledbr,HIGH);}

}
if(statusOld==0&&statusNew==1){
delay(50);
if(ledstatus==0){
digitalWrite(led,HIGH);
ledstatus=1;
}
else
{
digitalWrite(led,LOW);
ledstatus=0;
}
}
if(newtimerstate!= oldtimerstate)
{
if(newtimerstate==HIGH)
{
//delay(10);
timercount++;
c--;
state=0;
if(timercount>10){
timercount==10;
}
if(c==5){
digitalWrite(ledbr,LOW);
}
if(c==4){
digitalWrite(ledbr,LOW);
digitalWrite(ledgr,LOW);
}
if(c==3){
digitalWrite(ledbr,LOW);
digitalWrite(ledgr,LOW);
digitalWrite(ledg,LOW);
}
if(c==2){
digitalWrite(ledbr,LOW);
digitalWrite(ledgr,LOW);
digitalWrite(led,LOW);
digitalWrite(ledbl,LOW);
}
if(c==1){
digitalWrite(ledbr,LOW);
digitalWrite(ledgr,LOW);
digitalWrite(ledg,LOW);
digitalWrite(ledbl,LOW);
digitalWrite(ledgl,LOW);
digitalWrite(ledgreen,HIGH);
}

 }

}

statusOld=statusNew;
oldbuttonstate=newbuttonstate;
oldtimerstate=newtimerstate;
}

your link to an illustration of the circuit didn't work for me?

by diodes do you mean LEDs? of course "pushbuttons act like switches"??

not sure how switches, 555 and arduino work together

well so i dont have to hold the pushbutton down for the 555 to work. They act like a astable. It dident open when you clicked on it?

i learned about the 555 back in high in the 70s.

can you provide a better description of your circuit.

again, by diode, do you mean LED? if so, how are they connected?

here i have some pictures and the code now

Tinker link?

Post your code here.

Post a schematic of the ‘555 circuit here.

Your description is confusing at best. We not mind readers.

a7

Yes i know, Its hard do describe, sorry. If you could open it in tinkercad it would be easier to understand.

you could try by describing which pins of each component are connected to one another.

it sounds like you want to control the 555 (possibly take it out of reset) using an output pin from the arduino and the arduino monitors a pushbutton switch to determine when to enable the 555

i'm not sure how you can connect the LEDs (again are they LEDs) to 555 and yet have an arduino control which are active.

well the problem is to get the code right with right amount of blinks from the led to make the 5 leds go LOW.

What is the purpose of the 555? The arduino can easily generate a timed interval itself, using either the millis () or micros () functions, or the hardware timers.

because i wanted to try

you're not going to get much help the way you are responding.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.