Arduino – Week 1 – Software Notes

Pulse Width Modulation

 

 

Using ‘unsigned char’ to replace values

> ‘unsigned char’ allows you to control all of the same variables in a sketch by only changing one value

unsigned char DelayTime = 255;
unsigned char LEDoutput = 2;

// the setup function runs once when you press reset or power the board
void setup() {
 // initialize digital pin LED_BUILTIN as an output.
 pinMode(LED_BUILTIN, OUTPUT);
 pinMode(LEDoutput, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
 digitalWrite(LEDoutput, HIGH);
 digitalWrite(LED_BUILTIN, HIGH);
 delay(DelayTime);
 digitalWrite(LEDoutput, LOW);
 digitalWrite(LED_BUILTIN, LOW);
 delay(DelayTime);
 DelayTime = DelayTime - 10;
 }
Print Friendly, PDF & Email

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*