Please read the 'Current status' portion below: I know I need to fix something, but don't know what. The sketch is verified as it is below.
Any help/advice would be greatly appreciated.
Code:
/*
updown_fade
Fades an led up slowly, then back down slowly and utilizes condition statements
The circuit:
* LED (+) attached to pin 1. (3.3v w/ resistor)
* motion sensor 'signal' will be attached to pin 2 (for now I am just attaching and detatching a 3.3v lead to pin2)
* digispark microcontroller on breadboard (prototyping)
Created 7/15/2017
JAA
//Current status:
//The actual fading of the light (up & down) is working exactly how I want it to, but now I need to control it:
//When 3.3v is attached to pin2 it skips FADE IN and goes directly to HOLD:
//If I don't connect the 3.3v lead to pin2, it does skip FADE IN and delays 30 seconds with the led off as expected, but then continues to HOLD,:
//keeping the led at 250 for 5 min, instead of looping back and starting over.
//I am needing to clean up my controlling code to trigger the fading sequence via a digital 'HIGH' reading on pin 2 ?????:
// at which time it would go through the fading up & down sequence, then go back and check pin2 again.
//or (else) if pin 2 is 'LOW' delay for 30 seconds (30000) then loop and digitalread pin 2 again:
//I almost had it working, but was getting an error at } else { saying there was no 'if' preceeding it:
//I have taken it back to it's basic fading sequence and will wait for input from you all. Thanks for any help.
//By the way, this is my first sketch and my microcontroller is a digispark.
//In a nutshell, the light will have a PIR motion sensor that will send a signal to pin2 to 'trigger' the fading up/down sequence which will:
//last approx 7 minutes total, then wait for the trigger again and start all over:
*/
int sensorPin = 2; //motion sensor out pin connected to digital pin 2
int ledPin = 1; // LED connected to digital pin 1
int fadeValue = 0; //default brightness of led (variable)
void setup() {
// initialize the sensorPin as an input:
pinMode(sensorPin, INPUT);
// initialize the ledPin as an output:
pinMode(ledPin, OUTPUT);
}
void loop() {
//START
for (int fadeValue = 0 ; fadeValue <= 255 ; fadeValue += 1);
if(digitalRead(sensorPin)==HIGH) {
// sets the value (range from 0 to 255):
//FADE IN
// fade in from off to max in increments of 1 point:
analogWrite(ledPin, fadeValue);
// wait for .235 seconds then loop
delay(235);
} else {
delay(30000);
loop; }
{
//HOLD
//hold led at max brightness for 5 minutes
analogWrite(ledPin, 250);
delay(300000); }
//FADE OUT
// fade out from max to off in increments of 5 points:
for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 5) {
// sets the value (range from 0 to 255):
analogWrite(ledPin, fadeValue);
// wait for .25 seconds then loop
delay(588);}
}
Any help/advice would be greatly appreciated.