I have purchased an Arduino startup kit which includes the Arduino Uno R3 board. I have been working my way through "Arduino for Dummies"; I am now in the Button Sketch. I would like to add extra buttons to simulate a project having multiple inputs and outputs. I started with two - placed a button in parallel with the first, having its output leg sent to pin 3. I am using LEDs for loads.
The following sketch compiles, uploads and works exactly as desired; appropriate LED lights up when its button is pushed. However, even thought I'm using the supplementary power supply on the board, when I disconnect the RS232 cable, the circuit goes off and does its own thing (feat2out goes HIGH, ie. LED 2 goes on and stays on).
Is there something in the software to be written to keep a particular sketch loaded and operational in the UNO R3 when it is stand alone?
/*
Button
Turns on and off a light emitting diode(LED) connected to digital pin 8,
when pressing a pushbutton attached to pin 2. A delay has been incorporated
to provide a timed flash
This Sketch shows 2 button stages (features) to be operational
*/
const int feat1in = 2;
const int feat1out = 8;
const int feat2in = 3;
const int feat2out = 9;
int sig1in = 0;
int sig2in = 0;
void setup() {
pinMode(feat1out, OUTPUT);
pinMode(feat2out, OUTPUT);
pinMode(feat1in, INPUT);
pinMode(feat2in, INPUT);
}
void loop() {
// read the state of signal-in value:
sig1in = digitalRead(feat1in);
sig2in = digitalRead(feat2in);
if (sig1in == HIGH) {
digitalWrite(feat1out, HIGH);
delay(500);
digitalWrite (feat1out, LOW);}
else {
digitalWrite(feat1out, LOW);}
// read the state of signal_2-in value:
if (sig2in == HIGH) {
digitalWrite(feat2out, HIGH);
delay(500);
digitalWrite (feat2out, LOW);}
else {
digitalWrite(feat2out, LOW); }
}