Here is the sketch that I made. please correct me in any place that I am wrong. also, the time reset is now a pushbutton, setting the value to 5. This sketch does not work.
int timeVal = 0;
void setup() {
pinMode(8, OUTPUT);
pinMode(A0, INPUT);
}
void loop() {
timeval - 1
if(timeVal > 0){
digitalWrite(8, HIGH);
}
else{
digitalWrite(8, LOW);
}
if(A0, HIGH){
timeVal = 5;
}
}
Also, I have gained most of my knowledge of C# from Scratch. I am trying to use the same... components of the programming, if that makes any sense.
Your code doesn't compile because of the errors in the lines I have bolded up above.
1. You have not initialized the variable "timeval".... you obviously mean to use "timeVal" but the compiler can't read your mind like I can
. C++ variable names are case sensitive.
2. You did not terminate that line with a semicolon.
3. You have to explicitly read the A0 pin and use the conditional test == to compare to a value.
4. You need to tell it what to do if the conditional test fails (if A0 is LOW): include an else statement to reset timeVal.
So if you replace your line
timeval -1
with the line
timeVal -1;
or
timeVal --;
and the line
if(A0, HIGH){
with the line
if(digitalRead(A0)==HIGH){
and add the else statement
else timeVal=0;
after the final "if" statement
your sketch should compile and run.
But will it do what you intend? I think you will need to insert some delay() or test for some millis() values as Psi suggests. (His suggested pseudocode makes the same error about the capital V in timeVal though.)
If you don't intend to stay in bed for more than 50 days, I wouldn't worry about overflowing the millis() timer.