diff --git a/build/shared/examples/02.Digital/BlinkWithoutDelay/BlinkWithoutDelay.ino b/build/shared/examples/02.Digital/BlinkWithoutDelay/BlinkWithoutDelay.ino index ca4ac95fadd..3db1fcfe905 100644 --- a/build/shared/examples/02.Digital/BlinkWithoutDelay/BlinkWithoutDelay.ino +++ b/build/shared/examples/02.Digital/BlinkWithoutDelay/BlinkWithoutDelay.ino @@ -54,11 +54,7 @@ void loop() { previousMillis = currentMillis; // if the LED is off turn it on and vice-versa: - if (ledState == LOW) { - ledState = HIGH; - } else { - ledState = LOW; - } + ledState ^= HIGH; // set the LED with the ledState of the variable: digitalWrite(ledPin, ledState); diff --git a/build/shared/examples/02.Digital/Button/Button.ino b/build/shared/examples/02.Digital/Button/Button.ino index 33cc454f484..192df7b5a89 100644 --- a/build/shared/examples/02.Digital/Button/Button.ino +++ b/build/shared/examples/02.Digital/Button/Button.ino @@ -29,9 +29,6 @@ const int buttonPin = 2; // the number of the pushbutton pin const int ledPin = 13; // the number of the LED pin -// variables will change: -int buttonState = 0; // variable for reading the pushbutton status - void setup() { // initialize the LED pin as an output: pinMode(ledPin, OUTPUT); @@ -40,16 +37,6 @@ void setup() { } void loop() { - // read the state of the pushbutton value: - buttonState = digitalRead(buttonPin); - - // check if the pushbutton is pressed. - // if it is, the buttonState is HIGH: - if (buttonState == HIGH) { - // turn LED on: - digitalWrite(ledPin, HIGH); - } else { - // turn LED off: - digitalWrite(ledPin, LOW); - } -} \ No newline at end of file + // If the button is pressed, light up the LED: + digitalWrite(ledPin, digitalRead(buttonPin); +} diff --git a/build/shared/examples/02.Digital/DigitalInputPullup/DigitalInputPullup.ino b/build/shared/examples/02.Digital/DigitalInputPullup/DigitalInputPullup.ino index 7d9276b407b..588a202ca44 100644 --- a/build/shared/examples/02.Digital/DigitalInputPullup/DigitalInputPullup.ino +++ b/build/shared/examples/02.Digital/DigitalInputPullup/DigitalInputPullup.ino @@ -40,11 +40,7 @@ void loop() { // logic is inverted. It goes HIGH when it's open, // and LOW when it's pressed. Turn on pin 13 when the // button's pressed, and off when it's not: - if (sensorVal == HIGH) { - digitalWrite(13, LOW); - } else { - digitalWrite(13, HIGH); - } + digitalWrite(13, !sensorVal); } diff --git a/build/shared/examples/02.Digital/StateChangeDetection/StateChangeDetection.ino b/build/shared/examples/02.Digital/StateChangeDetection/StateChangeDetection.ino index 3e2f3b36508..f798cb08b5f 100644 --- a/build/shared/examples/02.Digital/StateChangeDetection/StateChangeDetection.ino +++ b/build/shared/examples/02.Digital/StateChangeDetection/StateChangeDetection.ino @@ -75,12 +75,7 @@ void loop() { // checking the modulo of the button push counter. // the modulo function gives you the remainder of // the division of two numbers: - if (buttonPushCounter % 4 == 0) { - digitalWrite(ledPin, HIGH); - } else { - digitalWrite(ledPin, LOW); - } - + digitalWrite(ledPin, buttonPushCounter % 4 == 0); }