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

  • You already know Dokkio is an AI-powered assistant to organize & manage your digital files & messages. Very soon, Dokkio will support Outlook as well as One Drive. Check it out today!

View
 

Lab 3 (1)

Page history last edited by xinyi xie 9 years, 9 months ago

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

 

We could either half all of the numbers in noteDurations[] or we could change the line delay(pauseBetweenNotes) to delay(pauseBetweenNotes/2) (or change 1.3 to .65 in the declaration of pauseBetweenNotes).

b. What song is playing? ;-)

 

The song is the theme from Star Wars.

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

 

I needed at least 5V. Even with 5V, with the highest potentiometer setting, it is difficult to see the words on the display.

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

 

I forgot to connect the 5V rails across the board. (I wired everything on the side of the arduino without a 5V power supply. I had connected the power supply to the red rail on the opposite side, but I hadn’t connected the red rails across the board.) I was able to fix this by connecting a wire between these rails.

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

 

lcd.print(“hello, world!”); can be changed to lcd.print(“Brian Knott”);

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

 

There are several ways to do this. Here is mine:

 

void loop() {

// read the value from the sensor:

sensorValue = analogRead(sensorPin);

// turn the ledPin on

analogWrite(ledPin, sensorValue/4);

// analogWrite maxes out 4 times withour this factor of 4

}

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

 

The multimeter reads 10.8 kΩ when the flex sensor is flat, 22.6 kΩ when bent.

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

 

We should expect 3.3*(10.8/37.8) = 0.94V when the flex sensor is flat. We should expect 3.3*(22.6/49.6) = 1.50V.

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

 

The change in the LED’s brightness from flat flex sensor to bent flex sensor is very hard to notice.

d. 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);

 

void setup() {

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

lcd.begin(16, 2);

// Print a message to the LCD.

lcd.print("hello, world!");

}

 

void loop() {

// Turn off the display:

lcd.noDisplay();

delay(500);

// Turn on the display:

lcd.display();

delay(500);

}

 

My LCD displays 444 when the flex sensor is flat and 495 when it is bent.

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

 

When the force sensor is not pressed, we see upwards of 10 MΩ across its terminals. When it is pressed hard, we see around 300 Ω.

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

 

The resistance does not appear to change linearly with the force. As soon as any force is applied, the resistance decreases to around 1 kΩ. It is hard to tell how extra force affects the resistance since it is difficult to apply a steady force to the sensor.

c. 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 = 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

 

void setup() {

// declare the ledPin as an OUTPUT:

pinMode(ledPin, OUTPUT);

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

lcd.begin(16, 2);

}

 

void loop() {

// read the value from the sensor:

sensorValue = analogRead(sensorPin);

// turn the ledPin on

analogWrite(ledPin, sensorValue/4);

// analogWrite maxes out 4 times withour this factor of 4

// Print a message to the LCD.

int s = sensorValue - 332;

if(s > 0) {

lcd.println("P1 is winning by");

lcd.setCursor(0, 1);

lcd.print(s);

} else if(s < 0) {

lcd.println("P2 is winning by");

lcd.setCursor(0, 1);

lcd.println(0-s);

} else {

lcd.print("The game is tied!");

}

delay(10);

lcd.clear();

}

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

Here is the 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; // 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 counter = 0;

int state = 0;

 

void setup() {

// declare the ledPin as an OUTPUT:

pinMode(ledPin, OUTPUT);

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

lcd.begin(16, 2);

}

 

void loop() {

// read the value from the sensor:

sensorValue = analogRead(sensorPin);

// analogWrite maxes out 4 times withour this factor of 4

// Print a message to the LCD.

 

int s = sensorValue - 332;

if(s > 0 && state == 0) {

state = 1;

counter++;

} else if(s < 0 && state == 1) {

state = 0;

}

lcd.print("Times Pressed:");

lcd.setCursor(0,1);

lcd.print(counter);

delay(10);

lcd.clear();

}

 

b. Post a link to theLab 3 Timers Hall of Fame.

Comments (0)

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