/* An improved version of the blink sketch. * blinkv3 * * Removing the use of LED_BUILTIN * Defining our pin * Understanding pinMode() * Understanding digitalWrite() * Understanding HIGH and LOW and it's alternatives * * pin 13 ...LED */ //const int is an int that cannot have it's value changed const int ledPin = 13;//pin 13 has a built in LED const int turnOnLED = 1; const int turnOffLED = 0; // the setup function runs once when you press reset or power the board void setup() { // Serial.begin(9600) starts serial communication. 9600bps bits per second = 1200 characters per second Serial.begin(9600); //Send script name Serial.println("blinkv3..."); //this will print a blank line Serial.println(" "); //The original LED_BUILTIN in has been removed as it can lead to bad habits in not defining a variable //Also it will not work on other makes of board. //pinMode(LED_BUILTIN, OUTPUT); pinMode(ledPin, OUTPUT);//A pin can be an INPUT or an OUTPUT } // the loop function runs over and over again forever void loop() { //this is good digitalWrite(ledPin, HIGH); // turn the LED on (HIGH is 5 volts) delay(1000); // wait for a second digitalWrite(ledPin, LOW); // turn the LED off by making the voltage LOW 0 volts delay(1000); // wait for a second //This code is good as it is clear what is happening //Turn the ledPin (pin 13) on (HIGH) with a variable turnOnLED that has a value of 1 (not equal to Zero) so could be -2, -200, +35, 64 digitalWrite(ledPin,turnOnLED); //wait half a second delay(500); //Turn the ledPin (pin 13) off (LOW) with a variable turnOffLED that has a value of 0 digitalWrite(ledPin,turnOffLED); delay(500); //Below is NOT a good way to write code, although the code works it would quickly become very confusing. //by calling pin 13 directly we no longer know what pin 13 does, this causes confusion in larger sketches digitalWrite(13, 1);//Although the value 1 makes the pin HIGH, it would be better with a variable name delay(500); digitalWrite(13, 0);//LOW equals 0 but again would be better with a variable name delay(500); }