From: Andrea Manni Date: Mon, 2 Mar 2015 16:11:17 +0000 (+0100) Subject: buttons reordered X-Git-Url: http://git.piffa.net/web?a=commitdiff_plain;h=6a0496fdc97f180319df0a3270d1a78920e7ec32;p=sketchbook_andrea buttons reordered --- diff --git a/basic/button_presses_LED_6/button_presses_LED_6.ino b/basic/button_presses_LED_6/button_presses_LED_6.ino deleted file mode 100644 index 771bbcc..0000000 --- a/basic/button_presses_LED_6/button_presses_LED_6.ino +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Alternating switch - */ - -int switchPin = 2; // switch is connected to pin 2 -int val; // variable for reading the pin status -int buttonState; // variable to hold the last button state -int lightMode = 0; // State of the light -int LED = 12; - -void setup() { - pinMode(switchPin, INPUT_PULLUP); // Set the switch pin as input - pinMode(LED, OUTPUT); - - buttonState = digitalRead(switchPin); // read the initial state - -} - - -void loop(){ - val = digitalRead(switchPin); // read input value and store it in val - delay(100); // Debounce - if ((val != buttonState) && (val == HIGH)) { // check if the button is pressed - lightMode = 1 -lightMode ; - } - digitalWrite(LED,lightMode); - buttonState = val; // save the new state in our variable -} - - - diff --git a/basic/button_presses_LED_blinking_deBounce_8/button_presses_LED_blinking_deBounce_8.ino b/basic/button_presses_LED_blinking_deBounce_8/button_presses_LED_blinking_deBounce_8.ino deleted file mode 100644 index 3116b42..0000000 --- a/basic/button_presses_LED_blinking_deBounce_8/button_presses_LED_blinking_deBounce_8.ino +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Turn on / off LED with a switch. - When the lightmode is on the LED Blinks - */ - -int switchPin = 2; // switch is connected to pin 2 -int val; // variable for reading the pin status -int valBounce ; // variable for debouncing -int buttonState; // variable to hold the last button state -int lightMode = 0; // State of the light -int LED = 12; - -void setup() { - pinMode(switchPin, INPUT_PULLUP); // Set the switch pin as input - pinMode(LED, OUTPUT); - - buttonState = digitalRead(switchPin); // read the initial state - -} - - -void loop(){ - val = digitalRead(switchPin); // read input value and store it in val - delay(10); // Debounce - valBounce = digitalRead(switchPin); // read input value and store it in val - - if ((val == valBounce) && (val != buttonState) && (val == HIGH)) { // check if the button is pressed - lightMode = 1 -lightMode ; // Now with DeBounce - } - if (lightMode) { // Check if light mode is TRUE == 1 or FALSE == 0 - delay(50); // Keep the LED LOW for 50ms - digitalWrite(LED,HIGH); // Blink the LED - delay(50); // Keep the LED HIGH for 50ms - // digitalWrite(LED,LOW); // We don't need to turn it LOW - // It will go off anyway later - } - - digitalWrite(LED,LOW); // Almayes turn off the LED - // As lightMode is FALSE == 0 turn the LED off - // Turn it off - buttonState = val; // save the new state in our variable -} - - - - - - - - diff --git a/basic/button_presses_LED_deBounce_7/button_presses_LED_deBounce_7.ino b/basic/button_presses_LED_deBounce_7/button_presses_LED_deBounce_7.ino deleted file mode 100644 index 1e0e203..0000000 --- a/basic/button_presses_LED_deBounce_7/button_presses_LED_deBounce_7.ino +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Alternating switch - */ - -int switchPin = 2; // switch is connected to pin 2 -int val; // variable for reading the pin status -int valBounce ; // variable for debouncing -int buttonState; // variable to hold the last button state -int lightMode = 0; // State of the light -int LED = 12; - -void setup() { - pinMode(switchPin, INPUT_PULLUP); // Set the switch pin as input - pinMode(LED, OUTPUT); - - buttonState = digitalRead(switchPin); // read the initial state - -} - - -void loop(){ - val = digitalRead(switchPin); // read input value and store it in val - delay(10); // Debounce - valBounce = digitalRead(switchPin); // read input value and store it in val - - if ((val == valBounce) && (val != buttonState) && (val == HIGH)) { // check if the button is pressed - lightMode = 1 -lightMode ; // Now with DeBounce - } - digitalWrite(LED,lightMode); - buttonState = val; // save the new state in our variable -} - - - - diff --git a/basic/button_presses_count_down_5/button_presses_count_down_5.ino b/basic/button_presses_count_down_5/button_presses_count_down_5.ino deleted file mode 100644 index 7e43837..0000000 --- a/basic/button_presses_count_down_5/button_presses_count_down_5.ino +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Alternating switch - */ - -int switchPin = 2; // switch is connected to pin 2 -int val; // variable for reading the pin status -int buttonState; // variable to hold the last button state -int buttonPresses = 10; // Counter for the button - -void setup() { - pinMode(switchPin, INPUT_PULLUP); // Set the switch pin as input - - Serial.begin(9600); // Set up serial communication at 9600bps - buttonState = digitalRead(switchPin); // read the initial state - Serial.println("Don not press the button! :P "); -} - - -void loop(){ - val = digitalRead(switchPin); // read input value and store it in val - delay(100); // Debounce - if ((val != buttonState) && (val == HIGH)) { // check if the button is pressed - buttonPresses-- ; - Serial.print("Press it an other "); - Serial.print(buttonPresses); - Serial.println(" times."); - } - if (buttonPresses == 0) { - Serial.println("----- > ExplOdE! <------"); - // Serial.flush(); // Print out the whole serial buffer - // exit(0); // Exit the sketch - } - buttonState = val; // save the new state in our variable -} - - diff --git a/basic/button_presses_counter_AND_4/button_presses_counter_AND_4.ino b/basic/button_presses_counter_AND_4/button_presses_counter_AND_4.ino deleted file mode 100644 index 6f5c373..0000000 --- a/basic/button_presses_counter_AND_4/button_presses_counter_AND_4.ino +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Alternating switch - */ - -int switchPin = 2; // switch is connected to pin 2 -int val; // variable for reading the pin status -int buttonState; // variable to hold the last button state -int buttonPresses = 0; // Counter for the button - -void setup() { - pinMode(switchPin, INPUT_PULLUP); // Set the switch pin as input - - Serial.begin(9600); // Set up serial communication at 9600bps - buttonState = digitalRead(switchPin); // read the initial state -} - - -void loop(){ - val = digitalRead(switchPin); // read input value and store it in val - delay(100); // Debounce - if ((val != buttonState) && (val == HIGH)) { // check if the button is pressed - buttonPresses++ ; - Serial.print("Button has been pressed "); - Serial.print(buttonPresses); - Serial.println(" times."); - } - buttonState = val; // save the new state in our variable -} - - diff --git a/basic/button_state_3/button_state_3.ino b/basic/button_state_3/button_state_3.ino deleted file mode 100644 index de29a13..0000000 --- a/basic/button_state_3/button_state_3.ino +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Alternating switch - */ - -int switchPin = 2; // switch is connected to pin 2 -int val; // variable for reading the pin status -int buttonState; // variable to hold the last button state - -void setup() { - pinMode(switchPin, INPUT); // Set the switch pin as input - - Serial.begin(9600); // Set up serial communication at 9600bps - buttonState = digitalRead(switchPin); // read the initial state -} - - -void loop(){ - val = digitalRead(switchPin); // read input value and store it in val - - if (val != buttonState) { // the button state has changed! - if (val == LOW) { // check if the button is pressed - Serial.println("Button just pressed"); - } else { // the button is -not- pressed... - Serial.println("Button just released"); - } - } - - buttonState = val; // save the new state in our variable -} diff --git a/basic/buttons/button_1/button_1.ino b/basic/buttons/button_1/button_1.ino new file mode 100644 index 0000000..5d840ec --- /dev/null +++ b/basic/buttons/button_1/button_1.ino @@ -0,0 +1,34 @@ +/* + Input + + Accensione e spegnimanto di un LED utilizzando un pin come input. + + + */ + +// Pin 13 has an LED connected on most Arduino boards. +// give it a name: +int led = 13; +int input = 8; + +// the setup routine runs once when you press reset: +void setup() { + // initialize the digital pin as an output. + pinMode(led, OUTPUT); // Il PIN e' attivato come output + pinMode(input, INPUT); // Il PIN e' attivato come output +} + +// the loop routine runs over and over again forever: +void loop() { + if (digitalRead(input) == HIGH) { // Verifica se il PIN input e' +5v + digitalWrite(led, HIGH); + } + else { // Alterativa: se non e' +5v + digitalWrite(led, LOW); + } +} + + +// Funzioni create dall'utente: + + diff --git a/basic/buttons/button_presses_LED_6/button_presses_LED_6.ino b/basic/buttons/button_presses_LED_6/button_presses_LED_6.ino new file mode 100644 index 0000000..771bbcc --- /dev/null +++ b/basic/buttons/button_presses_LED_6/button_presses_LED_6.ino @@ -0,0 +1,31 @@ +/* + * Alternating switch + */ + +int switchPin = 2; // switch is connected to pin 2 +int val; // variable for reading the pin status +int buttonState; // variable to hold the last button state +int lightMode = 0; // State of the light +int LED = 12; + +void setup() { + pinMode(switchPin, INPUT_PULLUP); // Set the switch pin as input + pinMode(LED, OUTPUT); + + buttonState = digitalRead(switchPin); // read the initial state + +} + + +void loop(){ + val = digitalRead(switchPin); // read input value and store it in val + delay(100); // Debounce + if ((val != buttonState) && (val == HIGH)) { // check if the button is pressed + lightMode = 1 -lightMode ; + } + digitalWrite(LED,lightMode); + buttonState = val; // save the new state in our variable +} + + + diff --git a/basic/buttons/button_presses_LED_blinking_deBounce_8/button_presses_LED_blinking_deBounce_8.ino b/basic/buttons/button_presses_LED_blinking_deBounce_8/button_presses_LED_blinking_deBounce_8.ino new file mode 100644 index 0000000..3116b42 --- /dev/null +++ b/basic/buttons/button_presses_LED_blinking_deBounce_8/button_presses_LED_blinking_deBounce_8.ino @@ -0,0 +1,50 @@ +/* + * Turn on / off LED with a switch. + When the lightmode is on the LED Blinks + */ + +int switchPin = 2; // switch is connected to pin 2 +int val; // variable for reading the pin status +int valBounce ; // variable for debouncing +int buttonState; // variable to hold the last button state +int lightMode = 0; // State of the light +int LED = 12; + +void setup() { + pinMode(switchPin, INPUT_PULLUP); // Set the switch pin as input + pinMode(LED, OUTPUT); + + buttonState = digitalRead(switchPin); // read the initial state + +} + + +void loop(){ + val = digitalRead(switchPin); // read input value and store it in val + delay(10); // Debounce + valBounce = digitalRead(switchPin); // read input value and store it in val + + if ((val == valBounce) && (val != buttonState) && (val == HIGH)) { // check if the button is pressed + lightMode = 1 -lightMode ; // Now with DeBounce + } + if (lightMode) { // Check if light mode is TRUE == 1 or FALSE == 0 + delay(50); // Keep the LED LOW for 50ms + digitalWrite(LED,HIGH); // Blink the LED + delay(50); // Keep the LED HIGH for 50ms + // digitalWrite(LED,LOW); // We don't need to turn it LOW + // It will go off anyway later + } + + digitalWrite(LED,LOW); // Almayes turn off the LED + // As lightMode is FALSE == 0 turn the LED off + // Turn it off + buttonState = val; // save the new state in our variable +} + + + + + + + + diff --git a/basic/buttons/button_presses_LED_deBounce_7/button_presses_LED_deBounce_7.ino b/basic/buttons/button_presses_LED_deBounce_7/button_presses_LED_deBounce_7.ino new file mode 100644 index 0000000..1e0e203 --- /dev/null +++ b/basic/buttons/button_presses_LED_deBounce_7/button_presses_LED_deBounce_7.ino @@ -0,0 +1,35 @@ +/* + * Alternating switch + */ + +int switchPin = 2; // switch is connected to pin 2 +int val; // variable for reading the pin status +int valBounce ; // variable for debouncing +int buttonState; // variable to hold the last button state +int lightMode = 0; // State of the light +int LED = 12; + +void setup() { + pinMode(switchPin, INPUT_PULLUP); // Set the switch pin as input + pinMode(LED, OUTPUT); + + buttonState = digitalRead(switchPin); // read the initial state + +} + + +void loop(){ + val = digitalRead(switchPin); // read input value and store it in val + delay(10); // Debounce + valBounce = digitalRead(switchPin); // read input value and store it in val + + if ((val == valBounce) && (val != buttonState) && (val == HIGH)) { // check if the button is pressed + lightMode = 1 -lightMode ; // Now with DeBounce + } + digitalWrite(LED,lightMode); + buttonState = val; // save the new state in our variable +} + + + + diff --git a/basic/buttons/button_presses_count_down_5/button_presses_count_down_5.ino b/basic/buttons/button_presses_count_down_5/button_presses_count_down_5.ino new file mode 100644 index 0000000..7e43837 --- /dev/null +++ b/basic/buttons/button_presses_count_down_5/button_presses_count_down_5.ino @@ -0,0 +1,36 @@ +/* + * Alternating switch + */ + +int switchPin = 2; // switch is connected to pin 2 +int val; // variable for reading the pin status +int buttonState; // variable to hold the last button state +int buttonPresses = 10; // Counter for the button + +void setup() { + pinMode(switchPin, INPUT_PULLUP); // Set the switch pin as input + + Serial.begin(9600); // Set up serial communication at 9600bps + buttonState = digitalRead(switchPin); // read the initial state + Serial.println("Don not press the button! :P "); +} + + +void loop(){ + val = digitalRead(switchPin); // read input value and store it in val + delay(100); // Debounce + if ((val != buttonState) && (val == HIGH)) { // check if the button is pressed + buttonPresses-- ; + Serial.print("Press it an other "); + Serial.print(buttonPresses); + Serial.println(" times."); + } + if (buttonPresses == 0) { + Serial.println("----- > ExplOdE! <------"); + // Serial.flush(); // Print out the whole serial buffer + // exit(0); // Exit the sketch + } + buttonState = val; // save the new state in our variable +} + + diff --git a/basic/buttons/button_presses_counter_AND_4/button_presses_counter_AND_4.ino b/basic/buttons/button_presses_counter_AND_4/button_presses_counter_AND_4.ino new file mode 100644 index 0000000..6f5c373 --- /dev/null +++ b/basic/buttons/button_presses_counter_AND_4/button_presses_counter_AND_4.ino @@ -0,0 +1,30 @@ +/* + * Alternating switch + */ + +int switchPin = 2; // switch is connected to pin 2 +int val; // variable for reading the pin status +int buttonState; // variable to hold the last button state +int buttonPresses = 0; // Counter for the button + +void setup() { + pinMode(switchPin, INPUT_PULLUP); // Set the switch pin as input + + Serial.begin(9600); // Set up serial communication at 9600bps + buttonState = digitalRead(switchPin); // read the initial state +} + + +void loop(){ + val = digitalRead(switchPin); // read input value and store it in val + delay(100); // Debounce + if ((val != buttonState) && (val == HIGH)) { // check if the button is pressed + buttonPresses++ ; + Serial.print("Button has been pressed "); + Serial.print(buttonPresses); + Serial.println(" times."); + } + buttonState = val; // save the new state in our variable +} + + diff --git a/basic/buttons/button_state_3/button_state_3.ino b/basic/buttons/button_state_3/button_state_3.ino new file mode 100644 index 0000000..de29a13 --- /dev/null +++ b/basic/buttons/button_state_3/button_state_3.ino @@ -0,0 +1,29 @@ +/* + * Alternating switch + */ + +int switchPin = 2; // switch is connected to pin 2 +int val; // variable for reading the pin status +int buttonState; // variable to hold the last button state + +void setup() { + pinMode(switchPin, INPUT); // Set the switch pin as input + + Serial.begin(9600); // Set up serial communication at 9600bps + buttonState = digitalRead(switchPin); // read the initial state +} + + +void loop(){ + val = digitalRead(switchPin); // read input value and store it in val + + if (val != buttonState) { // the button state has changed! + if (val == LOW) { // check if the button is pressed + Serial.println("Button just pressed"); + } else { // the button is -not- pressed... + Serial.println("Button just released"); + } + } + + buttonState = val; // save the new state in our variable +}