Hi all,
I just wanted to report that a quick test revealed that my suggestion is working.
Try it yourself... just a very quick test.
/*
Button
Just a proof, that it is possible to overcome the limitation of
the current Arduino Uno to look when permanently sending serial data.
Turns on and off a light emitting diode(LED, i.e. red) connected to digital
pin 13, when pressing a pushbutton attached to pin 2.
Turns on and off a LED (i.e. green) connected to digital pin 12,
when pressing a pushbutton attached to pin 3
Reads an analog input on pin 0, prints the result to the serial monitor
The circuit:
* red LED attached from pin 13 to ground
* green LED attached from pin 12 to ground
* pushbutton attached to pin 2 from +5V
* pushbutton attached to pin 3 from +5V
* 10K resistor attached to pin 2 from ground
* 10K resistor attached to pin 3 from ground
* 10K resistor attached to pin A0 from ground
* light dependent resistor attached to pin A0 from +5V
* Note: on most Arduinos there is already an LED on the board
attached to pin 13.
created 2005
by DojoDave <http://www.0j0.org>
modified 28 Oct 2010
by Tom Igoe
modified 2.11.2010
by KHK
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/Button
*/
// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 12; // the number of the LED pin
const int buttonPin2 = 3; // the number of the pushbutton pin
const int ledPin2 = 13; // the number of the LED pin
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
int buttonState2 = 0; // variable for reading the pushbutton status
void setup() {
Serial.begin(9600);
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
// initialize the LED pin as an output:
pinMode(ledPin2, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin2, INPUT);
}
void loop(){
// read analog input and prints to serial line
int sensorValue = analogRead(A0);
//Serial.println(sensorValue, DEC);
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
buttonState2 = digitalRead(buttonPin2);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
Serial.println(sensorValue, DEC);
}
else {
// turn LED off:
digitalWrite(ledPin, LOW);
}
// button 2 has no meaningful function at this moment
// besides switching on LED 2 when pressed
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState2 == HIGH) {
// turn LED on:
digitalWrite(ledPin2, HIGH);
}
else {
// turn LED off:
digitalWrite(ledPin2, LOW);
}
}
Cheers....
Karl-Heinz