4 – PWM a LED + Ideas for "Stupid Pet Trick" Project

This week we worked on developing code that would allow us to control the intensity of an LED's brightness based on the amount of force applied to a sensor.  By "squeezing" a round force sensitive recover (FSR) a human input was able to be computed from a force to an integer "read" and understood by the Arduino as wired on our breadboard.  This code is shared below:

//int fsrAnalogPin = 0; 
const int FSR = A0;
int LEDpin = 11;    
int fsrReading;    
int LEDbrightness;
int mapfsrReading ; 
 
void setup(void) {
    int fsrAnalogPin = 0; 
  pinMode(fsrAnalogPin, INPUT);
  Serial.begin(9600); 
  pinMode(LEDpin, OUTPUT);
}
 
void loop(void) {
  fsrReading = analogRead(FSR);
  //Serial.print("Analog reading = ");
  //Serial.println(fsrReading);
 
  LEDbrightness = map(fsrReading, 0, 1023, 0, 255); 
  analogWrite(LEDpin, LEDbrightness);
  Serial.println(LEDbrightness);
  
  delay(100);
}

An additional component of our weekly assignment was to brainstorm some concepts and research of sensors/actuators that we would like to complete as a midterm project.  This is known as "stupid pet trick" because the design is about the relationship between user experience and our ability to creatively code an interaction with our tools of code, Arduino, and external components.

Idea 1 – A game that responds to "breath" to levitate a ping pong ball.  The position of the ball signals a buzzer to emit a particular sound and the height of the ball is based on the force of a fan which is controlled by the power of the user's breath.  Sensors and components involved include a motor/fan, airflow sensor, and buzzers.

Idea 2 – An interactive display and art experience using ferrofluid.  Magnets on the underside of a tank or basin would move in response to a button or joystick moving by user interaction.  These magnets would then interact and "move" and activate ferrofluid that makes for a particular type of physical graphic interface.  Sensors and components needed would be servos and/or button(s).

Idea 3  – Daylight detection device that uses either servos and magnets or an electromagnet to create a visual composition in the presence or a defined value or "light" based on "outside conditions."  I am going to try this as my "Stupid Pet Trick" because I see a lot of interesting prototypes occurring for the overall experience and form matched to code.  A light sensor and servos and/or electromagnet(s) is required for this project to unfold.  I imagine laser cutting parts too and working in the shop.  The idea is to have iron filings arrange themselves into a particular "iconography" or pattern that a user can use to recognize a clear message – (ie.) "Light (sunnny)" or "Dark (cloudy)" – based on the "evaluated thresholds" of weather conditions and lighting environments.

3 – Coding Three Buttons (+/–/0)

This week, we built upon a code we started during class.  Originally, we we able to count the number of clicks, visually the value was seen by using a print command and boolean. This was done using one button and a resistor.  For homework, I had to wire three buttons and resistors with my breadboard and Arduino.  The code developed assigned a different function to each button.  One button will change the counter value by adding one.  A second button decreases the counter value by a change of subtracting one.  The last and third button is a 'reset' button that changes the value to 0.  

Shared below is my code and comments:

__________________________________

int counter = 0;  //defining the counter, from previous work

int butt3 = 4;    // button three, meaning it is in pin 4 on Arduino board
int butt2 = 3;    // button two, meaning it is in pin 3 on Arduino board
int butt1 = 2;    // button one, meaning it is in pin 2 on Arduino board

int buttValue3;    // I understand this step of button values to be defining a (set of) variable(s) that can be given value(s)
int buttValue2;    // ...as above...
int buttValue1;    // ...as above...

// these -int- above are now all universally "defined" and applied / "callable" from the written code below...
// "butt" is a shorthand for "button"

void setup() {
  pinMode(butt1, INPUT);
  pinMode(butt2, INPUT);
  pinMode(butt3, INPUT);
  Serial.begin(9600);
}

void loop() {
  buttValue1 = digitalRead(butt1);
  buttValue2 = digitalRead(butt2);
  buttValue3 = digitalRead(butt3);

  if (buttValue3 == 1) {
    counter = 0;
    Serial.println(counter);
  }
  if (buttValue2 == 1) {
    counter = counter - 1;
    Serial.println(counter);

  }
  if (buttValue1 == 1) {
    counter = counter + 1;
    Serial.println(counter);
  }

  delay(250);
}

2 – Arduino Haiku

This week, we wrote haikus.  However, in order to read the haiku a knob had to be turned to carrying degrees to have one of the three sentences (lines) appear on our computer screen.  Each line of the haiku was given a range within, what for me was, two thresholds; it would appear based on the values, known as potValue(s), detected on the Arduino circuit.  From power to sensor, it triggered one of three lines to print in the terminal on our computer screen.

Below is my code with comments and Haiku lines:

__________________________________________

int potPin = A0;
int potValue;
int threshold1 = 300;
int threshold2 = 900;

void setup() {
  pinMode(potPin, INPUT);
  Serial.begin(9600);
}

void loop() {
  potValue = analogRead(potPin);

if (potValue < threshold1){
  Serial.println("I want some pasta"); // line 1 .... three sentences of three different thoughts

}else if ((potValue > threshold1) && (potValue < threshold2)){ // the two objects to compare are within the (( )) values
    Serial.println("The sun is too bright for eyes"); // line 2
  } else {
    Serial.println("Shoes on way too tight"); // line 3
    
  }

  //Serial.print("The Pot Value is = "); 
  //Serial.println(potValue);
  delay(500); // standard is 10000 milliseconds equal to 1 second
}

// 1023 is the high and 0 is the low
// If lower than a thrshold, write the frist line of the Hiaku
// If other one than the second one...
// try random and see how the group of 5, 7, 5 syllable sentences, within context of a threshold, state a new sentence...

1 – Creative Switch

Capture the flag!  This week, I came up with a scenario.  This scenario was built upon our in class review of simple DC circuits.  Given a LED (light emitting diode), battery, copper tape, and wires it was asked that I build a circuit that had a switch.  This switch scenario is based on the icon of a flag and the game capture the flag.  

When inserted between the two wooden base pieces, the LED at the top of the flag pole illuminates and goes on.  This is because the battery provides power to the load which has leads that align to the leads connected to the power source.  I would like to build this out further and provide "holes" where the flag does not have the LED go on because the idea is to discover "where" the circuit can be completed and where it does not!

IMG_4960.jpeg
IMG_4961.jpeg