Hey thanks for the help! Wired everything up and it works. Sadly my coding doesn't work.
Code 1 with a sin has an error and doesn't function. Code 2, which is just the arduino.cc turtorial for fade, works great. Codes and error codes posted below.
If anyone could suggest a coding for making this fade on, hold on for 10 seconds, fade off and hold off for 10 seconds... I'd be incredibly appreciative.
I'm brand new to this, but trying to learn.
Thanks
The code that is returning an error: I am using this guiide and its code
When I upload with the code, i receive the error:
Arduino: 1.8.7 (Mac OS X), Board: "Arduino/Genuino Uno"
/Users/exhibits/Documents/Arduino/sketch_nov01c/sketch_nov01c.ino: In function 'void loop()':
sketch_nov01c:9:27: error: expected '}' at end of input
for(int i = 0; i<360; i++){ //convert 0-360 angle to radian (needed for sin function) float rad = DEG_TO_RAD * i; //calculate sin of angle as number between 0 and 255 int sinOut = constrain((sin(rad) * 128) + 128, 0, 255); analogWrite(fadePin, sinOut); delay(15); } }
^
sketch_nov01c:9:27: error: expected '}' at end of input
exit status 1
expected '}' at end of input
Invalid library found in /Users/exhibits/Documents/Arduino/libraries/sketch_nov01a: no headers files (.h) found in /Users/exhibits/Documents/Arduino/libraries/sketch_nov01a
Invalid library found in /Users/exhibits/Documents/Arduino/libraries/sketch_nov01a: no headers files (.h) found in /Users/exhibits/Documents/Arduino/libraries/sketch_nov01a
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
This is a copy of the code, unfortunately I don't think it was properly formatted:
//////////////////////////////////////////////////////////////////
//©2011 bildr
//Released under the MIT License – Please reuse change and share
//Simple code to output a PWM sine wave signal on pin 9
//////////////////////////////////////////////////////////////////
#define fadePin 3
void setup(){
pinMode(fadePin, OUTPUT);
}
void loop(){
for(int i = 0; i<360; i++){ //convert 0-360 angle to radian (needed for sin function) float rad = DEG_TO_RAD * i; //calculate sin of angle as number between 0 and 255 int sinOut = constrain((sin(rad) * 128) + 128, 0, 255); analogWrite(fadePin, sinOut); delay(15); } }
so i tried to reformat it to this:
#define fadePin 3
void setup(){
pinMode(fadePin, OUTPUT);
}
void loop(){
for(int i = 0; i<360; i++)
{ //convert 0-360 angle to radian (needed for sin function) float rad = DEG_TO_RAD * i;
//calculate sin of angle as number between 0 and 255 int sinOut = constrain((sin(rad) * 128) + 128, 0, 255);
analogWrite(fadePin, sinOut); delay(15); }
}
and then i receive the error:
Arduino: 1.8.7 (Mac OS X), Board: "Arduino/Genuino Uno"
/Users/exhibits/Documents/Arduino/sketch_nov01c/sketch_nov01c.ino: In function 'void loop()':
sketch_nov01c:15:24: error: 'sinOut' was not declared in this scope
analogWrite(fadePin, sinOut); delay(15); }
^
exit status 1
'sinOut' was not declared in this scope
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
Lastly, I used this code but I'm at a loss of how to tell it to stay on for 10 seconds following the fade and to stay off for 10 seconds following the fade:
int led = 3; // the PWM pin the LED is attached to
int brightness = 0; // how bright the LED is
int fadeAmount = 5; // how many points to fade the LED by
// the setup routine runs once when you press reset:
void setup() {
// declare pin 3 to be an output:
pinMode(led, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
// set the brightness of pin 3:
analogWrite(led, brightness);
// change the brightness for next time through the loop:
brightness = brightness + fadeAmount;
// reverse the direction of the fading at the ends of the fade:
if (brightness <= 0 || brightness >= 255) {
fadeAmount = -fadeAmount;
}
// wait for 30 milliseconds to see the dimming effect
delay(150);
}