Lab 3 - Cam Bennett


Make a Digital Timer!

 

Part A. Making Sounds

 

a. How would you change the code to make the song play twice as fast?

     On line 35 ( int noteDuration = 1000/noteDurations[thisNote];) change the 1000 to 500.  

b. What song is playing? ;-)

     The Star Wars Theme.

Part B. Writing to the LCD

 

a. What voltage level do you need to power your display?

     5V.

b. What was one mistake you made when wiring up the display? How did you fix it?

     The LCDs we were using had 18 pins instead of 16, so I mistakenly wired pins 13-16 instead of pins 11-14. To fix it, I simply used the right pins.

c. What line of code do you need to change to make it flash your name instead of "Hello World"?

      On Line 48 ( lcd.print("hello, world!");) change the text in the quotes to Cam.

Part C. Fancy Inputs

1. Potentiometer

a. Post a copy of your new code in your lab writeup.

     

int sensorPin = A0; 
int ledPin = 12;     
int sensorValue = 0;

 

void setup() {
  pinMode(ledPin, OUTPUT); 
  Serial.begin(9600);
}

void loop() {
  sensorValue = map(analogRead(sensorPin), 0, 1023, 0, 255);
  analogWrite(ledPin, sensorValue); 
  delay(10);                   
}

2. Flex Sensor

 

a. What resistance do you see with a Multimeter when the sensor is flat? When it is bent?

     11K Ohms when it is flat, aroudn 25K Ohms when bent at a right angle.

b. What kind of voltages should we expect for the Teensy analog pin based on the sensor resistance?

     Assuming the flex sensor is connected to 5 volts, 3.3 volts when it is flat and 2.5 when bent(approximately).

c. How does the range of the LED's brightness change compared to the potentiometer?

     The range of the brightness change is much less than with the pot. 

d. Include a copy of your Lowly Multimeter code in your lab write-up.

 

#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int sensorPin = A8; 
int sensorValue = 0;


void setup() {
  lcd.begin(16, 2);
  Serial.begin(9600);
}

void loop() {
  sensorValue = analogRead(sensorPin);
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print(sensorValue);
  delay(20);                   
}

3. Force Sensitive Resistor

 

Just like the Flex sensor, the FSR changes resistance—in this case, when pressure is applied to the FSR. Here's the datasheet. We can reuse the same circuit as before. (It's okay to remove the LED, though.)

 

Now build two FSR circuits to enable a game of thumb wrestling. Take another FSR from the parts shelf, but be sure to return it when done! (We don't have enough for everyone to have 2). Use the LCD to indicate who is squeezing their FSR harder!

a. What resistance values do you see from your force sensor?

     Resistance is infinite when untouched. When depressed with superhuman strength like my own, it drops to around 250 KOhms.

b. What kind of relationship does the resistance have as a function of force applied? (e.g., linear?)

     The relationship is not linear. It's going ok, although resistance wants to live together and force is still a bit afraid of commitment. In actuality, the graph would look something like resistance = constant/force, as resistance drops very quickly with a little force but slows its decrease eventually. At very high forces, the amount of force required to decrease resistance by even 1K Ohm is high.

c. Include a copy of your FSR thumb wrestling code in your lab write-up.

#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int sensorPinA = A8;
int sensorPinB = A7;
int sensorValueA = 0;
int sensorValueB = 0;


void setup() {
  lcd.begin(16, 2);
  Serial.begin(9600);
}

void loop() {
  sensorValueA = analogRead(sensorPinA);
  sensorValueB = analogRead(sensorPinB);
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print(sensorValueA);
  lcd.print("\t");
  lcd.print(sensorValueB);
  lcd.setCursor(0,1);
  if(sensorValueA > sensorValueB) {
    lcd.print("Player 1 Wins!!!!");
  } else if (sensorValueB > sensorValueA) {
    lcd.print("Player 2 Wins!!!!");
  } else {
    lcd.print("Tie");
  }
  delay(20);                   
}

 

Part D. Timer

a. Make a short video showing how your timer works, and what happens when time is up! -0.5

http://www.youtube.com/my_videos_edit?ns=1&video_id=IjsVZ01-f1Y

b. Post a link to the Lab 3 Timers Hall of Fame.