PCOMP Week 3

This week’s assignment is to make an Arduino circuit which has digital input and output. Actually, I misunderstood last week’s assignment and made circuits working with switches instead of making switch itself. So this time, I created a switch type digital input/output circuit to make up for the missing one.

So first, I came up with several ideas for the switch:

There were various concepts such as a switch like a puzzle or a dart game, but I want something that has a meaning to be coded. Therefore, I decided to make a circuit that responses differently depending on the combination of inputs and the chosen idea was a switch that the user can control the blinking pattern and the colour of the bulbs using six switches.

I thought this wasn’t that complicated but actually, it was. My original thought was to make a circuit that had three switches with diverse numbers and other three switches with variable colours, and if a user brings one number switch and one colour switch into contact, then the switch in that colour blinks in a specific pattern. However, while I drew the schematic diagram, I realised that it might have not possible to design such circuit. To have it work like that, each switch on it must have two inputs, though I only know how to make a switch with one digital input. So I changed my plan. Instead of making two switches directly touch each other, I added sort of a power stage that both two types of switches can be on and get the electricity.  

This is the final diagram:

Before getting started, I tried rather a simple one with a simple on/off code.

Then, for the targeted circuit, I made six cardboard buttons using a laser cutter. I didn’t have to but just wanted to try it once.

And following is the intermediate result. I covered an abandoned box with brass tape to use it as a power stage:

In this case, the switch that stands for yellow and the switch no. 2 are on the stage, so the yellow LED shortly blinks twice at a time.

I added remaining switches and the final result is like below:

I tried to hide the boards in a box and arrange them more neatly but failed. I now understand the difficulties that hardware designers have. It worked as I intended, anyway. It also does some math!

It doesn’t respond immediately from time to time. I suppose it’s because the stage is a bit too large to conduct electricity smoothly.

The full code for this circuit is like below:

#define redLED 2
#define yellowLED 3
#define greenLED 4
#define switch1 7
#define switch2 6
#define switch3 5
#define redSwitch 10
#define yellowSwitch 9
#define greenSwitch 8
void setup() {
Serial.begin(9600); // basic communication speed
// SETTING INPUTS
pinMode(switch1, INPUT);
pinMode(switch2, INPUT);
pinMode(switch3, INPUT);
pinMode(redSwitch, INPUT);
pinMode(yellowSwitch, INPUT);
pinMode(greenSwitch, INPUT);
// SETTING OUTPUTS
pinMode(redLED, OUTPUT);
pinMode(yellowLED, OUTPUT);
pinMode(greenLED, OUTPUT);
}
void loop() {
int switch1State = digitalRead(switch1);
int switch2State = digitalRead(switch2);
int switch3State = digitalRead(switch3);
int redSwitchState = digitalRead(redSwitch);
int yellowSwitchState = digitalRead(yellowSwitch);
int greenSwitchState = digitalRead(greenSwitch);
int nBlink = 0;
// CALCULATING THE NUMBER OF BLINKING
if(switch1State == HIGH) nBlink += 1;
if(switch2State == HIGH) nBlink += 2;
if(switch3State == HIGH) nBlink += 3;
if(nBlink>0 && redSwitchState == HIGH) {
for(int i=0; i<nBlink; i++) { digitalWrite(redLED, HIGH); delay(500); digitalWrite(redLED, LOW); delay(100); } delay(900); } if(nBlink>0 && yellowSwitchState == HIGH) {
for(int i=0; i<nBlink; i++) { digitalWrite(yellowLED, HIGH); delay(500); digitalWrite(yellowLED, LOW); delay(100); } delay(900); } if(nBlink>0 && greenSwitchState == HIGH) {
for(int i=0; i<nBlink; i++) {
digitalWrite(greenLED, HIGH);
delay(500);
digitalWrite(greenLED, LOW);
delay(100);
}
delay(900);
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *