Workshop_03 ↓ Physical Computing

During the Physical Computing Workshop part 3/5, we had to try out modules in small groups. I tested the Sparkfun Easy Driver + Stepper Motor and the MPR121 Capacitive Touch Sensor, both pretty enjoyable to play with — well, that’s it if you don’t mix-up the wires and smell the burn…

For the homework, I had to use something I didn’t get to try previously so I chose the Servo Motor. Setting it up was pretty easy following this tutorial, and the Servo Motor swept back and forth without any trouble.

I added a Potentiometer to control this Servo Motor, and it still works out pretty well. On top of that, I added a LED that is also controlled by the Potentiometer to make it fade. However, I feel that the input of the two components are having a face-to-face and somehow cancel the fade effect…? The Potentiometer still lights up the LED at the end of its turn though.

Before I reach out to a solution, here the code ↓↓↓


Servo myservo;
const int potpin = 0;
int angle = 0;

const int ledPin = 10;
int brightness = 0;
int fade = 0;

void setup() {
pinMode(ledPin, OUTPUT);

void loop() {
angle = analogRead(potpin);
angle = map(angle, 0, 1023, 0, 180);

brightness = analogRead(potpin);
fade = map(brightness, 0, 1023, 0, 255);
analogWrite(ledPin, fade);

And the video ↓↓↓

On another note, this module seems pretty similar that of the Stepper Motor, but it is not as precise — the Stepper Motor is defined by steps and you can choose the angle of each step, while the Servo Motor turns around at once. Hence it seems to have less possibilities, but certainly I wasn’t able to make full use of it.

Workshop_02 ↓ Physical Computing

The exercice was to to do an intervention using what we’ve learned during last week’s class, aka the use of the push button and the potentiometer with LEDs.

I got in my possession a RGB LED that I’ve really wanted to try out. Basically, I wanted the push button to light on / off the LED, and the potentiometer to change the RGB value of the LED.

The RGB LED got 4 legs, the 2nd leg which is the longest one is (-) while the others legs are (+). I connected the three (+) legs into the digital input, and the (-) into the ground. For each (+) leg, I used a 330Ω resistor.

Then, I connected the push button and the potentiometer, following what I’ve been taught previously. I used a 10KΩ resistor for the push button.

Here is the code ↓↓↓

int redPin = 1;
int greenPin = 2;
int bluePin = 3;

int buttonPin = 7;
int potPin = A0;

int val = 0;

boolean ledState = LOW;
boolean prevBtnState = LOW;

void setup() {
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);

pinMode(buttonPin, INPUT);
pinMode(potPin, INPUT);

void setColor (int red, int green, int blue) {
analogWrite(redPin, 255 - red);
analogWrite(greenPin, 255 - green);
analogWrite(bluePin, 255 - blue);

void loop() {
boolean btnState = digitalRead(buttonPin);
int val = analogRead(potPin);

if (btnState == HIGH && prevBtnState == LOW) {
if (val < 100) {
setColor(255, 0, 0);
if (val >= 100) {
setColor(0, 255, 0);
if (val > 400) {
setColor(0, 0, 255);

digitalWrite(redPin, ledState);
digitalWrite(greenPin, ledState);
digitalWrite(bluePin, ledState);

//prevBtnState = btnState;

I’ve followed last week’s code to write this new one, and I researched tutorials (notably on Adafruit) to implement the RGB LED’s part.

However, it didn’t work out exactly the way I wanted since I can’t seem to work out the part where the switch stays on / off until its next state’s change. I can’t figure it out for now but it still works for the most part. Hopefully, as I get more comfortable with Arduino, I’ll get back to it later and solve it.