hey there so i wanna set a timer to make it work for some time but i don't know why it doesn't work it seems to work for one time when i put "while(1){}" at the end of the if statement but i don't want it to work for one time then never opens again can anyone help? CODE:
#include <Arduino.h>
// put function declarations here:
int myFunction(int, int);
int input= 7 ;
int led= 12 ;
int inputstorage=0;
int time=5000000000;
void setup() {
// put your setup code here, to run once:
pinMode(6,OUTPUT);
pinMode(7,INPUT);
}
void loop() {
inputstorage=digitalRead(input);
if(inputstorage==true)
{
digitalWrite(led,true);
delay(400);
digitalWrite(led,false);
} else
{
digitalWrite(led,false);
inputstorage==true;
}
}
1. You should use code tags (<>)to post your sketch in the following format:
#include <Arduino.h>
// put function declarations here:
int myFunction(int, int);
int input = 7 ;
int led = 12 ;
int inputstorage = 0;
int time = 5000000000;
void setup()
{
// put your setup code here, to run once:
pinMode(6, OUTPUT);
pinMode(7, INPUT);
}
void loop()
{
inputstorage = digitalRead(input);
if (inputstorage == true)
{
digitalWrite(led, true);
delay(400);
digitalWrite(led, false);
}
else
{
digitalWrite(led, false);
inputstorage == true;
}
}
2. I understand that you have a Push Button connected at DPin-7 with an external pull-down resistor and a LED at DPin-12 (Fig-1). Your sketch of Step-1 does not match with Fig-1.

Figure-1:
3. Do you want that when the Button is pressed, LED will turn On and remain On for 5-sec (for example) and then goes Off?
sorry i am new to this also yes replying to your 3rd 1. question
yeah i was just messing around with the number limt i knew they wont work
i also use a simulator because i don't want to burn anything with my real board here is the picture of it it might be confusing
because i dont know how to colour code it
1. Be sure that your hardware setup agrees with Fig-1 of post #5.
2. Upload the following sketch (your one with some modification).
int input = 7 ;
int led = 12 ;
int inputstorage = 0;
unsigned int time = 5000; //5000 ms = 5-sec
void setup()
{
// put your setup code here, to run once:
pinMode(led, OUTPUT);
pinMode(input, INPUT);
digitalWrite(led, LOW);
}
void loop()
{
inputstorage = digitalRead(input);
if (inputstorage == HIGH)
{
digitalWrite(led, HIGH);
delay(time);
digitalWrite(led, LOW);
}
}
3. Gently, press the Button.
4. Check that LED is On or 5-sec.
5. Check that LED has gone Off.
6. Repeat the process.
it works thank you so much
You can now use this working project as a Building Block to build many more simple to complex projects as the desire arises in your mind.
The attached file may worth reading and practicing.
Ch-4DIOLec.pdf (657.1 KB)