Lab 2: Input/output

For my second lab assignment, I connected a digital input and output circuit and an analog input circuit. (images below) The difference between a digital input and an analog input is that digital input can only sense two states (that’s why it’s also called binary input), on and off, and analog input can read a variable voltage. The range of an analog input is usually between 0 and the maximum voltage that the micro-controller can take. But the range can change depending on the physical context. In these instances, I should use the real range rather than the maximum range of the analog sensor.

There are various differences in working with digital input versus analog input. For one, an analog input requires an analog-to-digital converter (ADC) to read the voltage change and convert it into digital form, because the micro-controller can only read two input values, 0V and 5V. The ADC is built in the Arduino. With a digital input there is not need to convert the voltage.

Secondly, an analog input is less stable than a digital input. To smooth out the dips and spikes that goes into the circuit when inputing with an analog sensor, I need to decouple the input with a decoupling capacitor. (Capacitors are used to smooth out signals, by storing energy when the current is passing through and releasing it later.) Also, I should introduce a small delay after reading each sensor, to give the micro-controller time to stabilize before reading the next sensor.

Digital output is pretty straightforward – it turns something, such as a LED, on or off.

Issues: 

  • I had some issues with digital I/O when I tried to make my own switch with metal sheets. The LEDs lit and responded to the switch, but didn’t follow the correct order of the program, i.e. yellow off, red on when switch is off and the reverse then the switch is on.

Questions:

  • I’m still not sure how to find the real range of an analog sensor in practice.
  • I had encountered debouncing in another class when we used the Flora. What’s the difference between decoupling and debouncing?
  • How do you know which size of decoupling capacitor to use in an analog input circuit?

Other:

  • I briefly looked at the serial monitor for input data, but I still don’t totally understand how it works. I’ll look more into that.
Digital I/O

Digital I/O

Digital I/O with one button.

Digital I/O with one button.

Digital I/O with DIY button. **Issue: both LEDs are lit when the switch is off, when the yellow LED should be off.

Digital I/O with DIY button. **Issue: both LEDs are lit when the switch is off, when the yellow LED should be off.

Digital I/O with DIY switch2. **Issue: again, both LEDs are lit when the switch is off.

Digital I/O with DIY switch2. **Issue: again, both LEDs are lit when the switch is off.

Analog input.

Analog input.

Analog input with a potentiometer.

Analog input with a potentiometer.

Analog input with a force sensing resistor.

Analog input with a force sensing resistor.

 

 

First encounter with the Flora

This class works really well in parallel with Physical Computing. While we delve more into the basics of electronics in P Comp, we jumped right into implementing simple interactions with the Flora in the second part of the Costumes class. We used pre-existing code that Kaho provided to light up a LED on the Flora with the press of a button.

Lighting up LED with one switch.

Lighting up LED with one switch.

Lighting up LED with two buttons.

Lighting up LED with two buttons.

It was fairly easy to make adjustments to the code and configurations of the connections to try various ways of lighting up the LED and even to input text with a button.

jia

Printing strings by pressing on a switch.

Printing strings with DIY switch.

Printing strings with DIY switch.

We also tried using conductive fabric and material as a switch. One of the takeaway from this was that, because contact from fabric is not as secure as a conventional switch, we need to “debounce” in the code to make the response more stable. Debouncing checks the lastButtonState and ensure that it’s different from the current buttonState. Again, we used pre-existing code to do this. I’ll need to look more into this to have a better understanding. There was a lot of tickering around with the code and connections until things worked. I’m making baby steps to building my own mind altering costume.

 

MineSweeper

Screen Shot 2014-09-10 at 8.07.09 AMThis is my first assignment for ICM.

I first started playing around with shapes in for loops. These are a few of the patterns that I created.

 

exercises

The red triangles reminded me of the flags in the game Minesweeper, so I turned them into flags, like this.

flagflagflagflagflagflagflagflagflagflagflagflagflag

Then added abstracted explosions with yellow triangles and lines.

***** code *****

void setup() {
size (700, 600);
background(255);
}

void draw() {
fill(255, 0, 0, 150);
//noStroke();
smooth();

for (int y = 30; y < height-30; y += 15) {
for (int x = 35; x < width-35; x += 13) {

/*fill(0-y);
noStroke();
triangle(x+11, y, x+6.5, y+8, x+15.5, y+8);
//fill(255, y-150, x-y, 150);*/

// flags
fill(255, 0, 0);
noStroke();
triangle(x-1, y, x+8, y-4, x+8, y+4);

stroke(0);
strokeWeight(1);
line(x+7, y+4, x+7, y+6);
line(x+2, y+7, x+7, y+7);
strokeWeight(2);
line(x+1, y+9, x+9, y+9);

stroke(y+50, y+50, y+50);
line(x-1, y, 300, 240);
}
}

//stroke(80);
rect(278, 238, 44, 44);
fill(150);

//bomb
fill(0);
noStroke();
ellipse(300, 260, 20, 20);

fill(255);
noStroke();
ellipse(296, 256, 5, 5);

//top
stroke(0);
strokeWeight(2);
line(300, 249, 300, 245);

//bottom
line(300, 271, 300, 275);

//left
line(289, 260, 285, 260);

//right
line(311, 260, 315, 260);

strokeWeight(2);
//top left
line(289, 248, 293, 252);

//top right
line(311, 248, 308, 251);

//bottom left
line(288, 272, 291, 269);

//bottom right
line(311, 272, 308, 269);

}