In developing new products, electronics designers are always improving designs by adding features and functions that excite the customer. The Trick Switch device you built can be improved by adding an LED indicator. This LED indicates when the Trick Switch timing cycle is done. Figure 1-3 shows you where to add a green LED to the Trick Switch on the full-size clear breadboard.
Figure 1-3. Adding a green LED indicator to the Trick Switch circuit built on a full-size clear breadboard
To complete the new product design, you need to make a few changes to the Pushbutton sketch. Modify the sketch using the code changes shown in Example 1-2.
Example 1-2. Pushbutton sketch modified to include LED indicators
// 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 ledPin13 = 13; // onboard LED
void setup() {
// initialize the LED pins as outputs:
pinMode(ledPin, OUTPUT);
pinMode(ledPin13, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}
void loop(){
// read the state of the pushbutton value:
int buttonStatus;
buttonStatus = digitalRead(buttonPin);
// check if the pushbutton is pressed
// if it is, the buttonStatus is HIGH:
if (buttonStatus == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
// turn off onboard LED:
digitalWrite(ledPin13,LOW);
}
else {
// turn LED off:
digitalWrite(ledPin, LOW);
// turn on onboard LED:
digitalWrite(ledPin13, HIGH);
}
}
After you’ve saved the sketch changes and uploaded them to the Arduino, the green LED will turn on. When you press the mini pushbutton, the green LED will turn off, and the red LED will turn on. Pretty awesome stuff. Enjoy!
The block diagram in Figure 1-4 shows the electronic component blocks and the electrical signal flow for the Trick Switch. A Fritzing electronic circuit schematic diagram of the switch is shown in Figure 1-5. Electronic circuit schematic diagrams are used by electrical/electronic engineers to design and build cool electronic products for society.
Figure 1-4. Trick Switch block diagram
Leave a Reply