Examples - Sensorboard - Buttons
Buttons
This Example shows the use of Buttons.
/************************************************************************************************** * * Buttons * * Version: 1.0.0 - September 2008 * Author: Etienne Ribeiro / tutorial assistant caad / eribeiro[at]ethz.ch * Supervisor: Christoph Wartmann / chair for caad - ETH Zürich / wartmann[at].arch.ethz.ch * * Desc: Shows the use of Buttons. * ***************************************************************************************************/ // Const static int pinDigitalIn1 = 16; static int pinDigitalIn2 = 17; static int pinOut1 = 18; static int pinOut2 = 19; static boolean enableSerial = false; // Setup void setup() { // LED (2 * blink) pinMode(48, OUTPUT); digitalWrite(48, HIGH); delay(200); digitalWrite(48, LOW); delay(200); digitalWrite(48, HIGH); // Serial (Print to serial if enableSerial = true) if (enableSerial == true) Serial.begin(9600); // pinMode pinMode(pinDigitalIn1, INPUT); pinMode(pinDigitalIn2, INPUT); pinMode(pinOut1, OUTPUT); pinMode(pinOut2, OUTPUT); } // Loop void loop() { // Read: int val1 = digitalRead(pinDigitalIn1); int val2 = digitalRead(pinDigitalIn2); // LED on/off: if(val1 == HIGH) { digitalWrite(pinOut1, HIGH); } else { digitalWrite(pinOut1, LOW); } if(val2 == HIGH) { digitalWrite(pinOut2, HIGH); } else { digitalWrite(pinOut2, LOW); } // Debug: if (enableSerial == true) { Serial.print(" Value 1: "); Serial.print(val1, DEC); Serial.print(" Value 2: "); Serial.print(val2, DEC); Serial.println(""); } // Wait: delay(50); }