| 
  • If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • Stop wasting time looking for files and revisions. Connect your Gmail, DriveDropbox, and Slack accounts and in less than 2 minutes, Dokkio will automatically organize all your file attachments. Learn more and claim your free account.

View
 

Kellen Asercion Lab 3 Writeup

Page history last edited by asercion@stanford.edu 7 years, 6 months ago

A)

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

 

The notes are played for 1000/(noteDurations).  If we change the 1000 to 500, or double each of the values in the noteDurations array, each note will be halved.  We also need to halve the delay time between notes in order to get the melody to play at truly twice the speed.

 

1b. What song is playing? ;-)

 

Star Wars main theme

 

B)

1a. 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?

 

I didn't make any mistakes when wiring up the display.

 

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

 

We would need to change the string in the line: lcd.print("hello, world!");

 

C)

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

 

int sensorPin = A0;    // select the input pin for the potentiometer

int ledPin = 13;      // select the pin for the LED

int sensorValue = 0;  // variable to store the value coming from the sensor

int brightness = 0;   // LED brightness

 

void setup() {

  // declare the ledPin as an OUTPUT:

  pinMode(ledPin, OUTPUT);  

}

 

void loop() {

  // read the value from the sensor:

  sensorValue = analogRead(sensorPin);    

  brightness = sensorValue/4; // Since brightness is between 0 and 255, divide the analog input by 4

  analogWrite(ledPin, brightness);         

}

 

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

 

About 20 kOhms to about 60 kOhms

 

2b) What kind of voltages should we expect for the Arduino analog pin based on the sensor resistance?

 

We created a voltage divider with our flex sensor and a 24k resistor.  Since our flex sensor's minimum resistance is about 20k, our max voltage is about 1.8V and our min voltage is about 1V.

 

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

 

The brightness would be dimmer because of the increased resistance.

 

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

// include the library code:

#include <LiquidCrystal.h>

 

// initialize the library with the numbers of the interface pins

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

int sensorPin = A0;

int sensorValue = 0;

 

void setup() {

  // set up the LCD's number of columns and rows: 

  lcd.begin(16, 2);

  lcd.print("Voltage");

}

 

void loop() {

  sensorValue = analogRead(sensorPin);

 

  float slope = -0.005285;

  float intercept = 3.4207;

  float voltage = slope*sensorValue + intercept;

 

  // Print a message to the LCD.

  lcd.setCursor(0,1);

  lcd.print(voltage);

}

 

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

 

70 kOhms at the start.  When depressed goes down to ~250 Ohms, when released goes back up to 10 kOhms.

 

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

 

I think it is some kind of exponential relationship.  

 

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

 

// include the library code:

#include <LiquidCrystal.h>

 

// initialize the library with the numbers of the interface pins

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

int sensorPin_1 = A0;

int sensorPin_2 = A1;

int sensorValue_1 = 0;

int sensorValue_2 = 0;

 

void setup() {

  // set up the LCD's number of columns and rows: 

  lcd.begin(16, 2);

  lcd.print("P1            P2");

}

 

void loop() {

  sensorValue_1 = analogRead(sensorPin_1);

  sensorValue_2 = analogRead(sensorPin_2);

 

  // Print a message to the LCD.

  lcd.setCursor(0,1);

  lcd.print(sensorValue_1);

  lcd.setCursor(13,1);

  lcd.print(sensorValue_2); 

}

 

D)

For the digital timer I modified the thumb wrestling game to make it more fun.  The game is started by pressing a button.  Then there is some text explaining the rules and a countdown to the start of the game.  Players have 5 seconds to press the force sensors as hard as they can.  when time is up, the screen shows who won and that person's LED lights up.

 

 

Video of Timer

 

Comments (0)

You don't have permission to comment on this page.