Hey there!
so I was bored and testing my PWM skills and with no attachments but an arduino board, trying to get LED13 to accept PWM settings, eventually I hacked for an hour or so trying to use the example "Fade" and I wasn't getting closer to understanding it.
so I made my own Pulse Width Modifier code for digital outputs (specifically LED13).
I hope you liekss.
(probably should be in a different location because I dont need help [I dont know where], I am just so proud of some of my first arduino codings and first coding in years and years and years, compliments to the chef - language and reference and even randoms on forums discussing code are very easy to read and understand!)
void setup() {
Serial.begin(9600);
//I like to talk to my arduino and have it report back to me
}void loop(){
Serial.println("start");
int ledPin=13; // uses arduino D13 LED
pinMode(ledPin, OUTPUT); // sets the digital pin as output
float DelayValue = .5; // increment of power
float TimeofFade = 25; // width of one pulse
// total length of time from 0 to 100% is (TimeofFade/DelayValue)TimeofFade (TOF/DV is the number of times the loop is completed, * length of time in the loop)
// in this case 25/.5 = 50/1 = 5025 = 1250ms
// total loop time is 2500 + the two delays between increase and decrease the middle to add smoothness//this is going from 0->100
for(float FadeValue=0; FadeValue <= TimeofFade; FadeValue += DelayValue) {
digitalWrite(ledPin, HIGH);
delay(FadeValue); // ON for the incrementing FadeValue
digitalWrite(ledPin, LOW);
delay(TimeofFade-FadeValue); // OFF for the decrementing remaining "pulse width"
// Serial.println(FadeValue);
}
digitalWrite(ledPin, HIGH); delay (TimeofFade);//this is going from 100->0
for(float FadeValue=TimeofFade; FadeValue >=0; FadeValue -=DelayValue){
digitalWrite(ledPin, HIGH);
delay(FadeValue); // ON for the decrementing FadeValue
digitalWrite(ledPin, LOW);
delay(TimeofFade-FadeValue); // OFF for the incrementing remaining "pulse width"
// Serial.println(FadeValue);
}
digitalWrite(ledPin, LOW); delay (TimeofFade);
}
what do you think?