| 
  • 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
 

Cole Hoffer - Lab 3

Page history last edited by xinyi xie 6 years ago

Part A. Making Sounds

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

Double the speed of the noteDuration by changing 1000/ to 500/

int noteDuration = 1000/noteDurations[thisNote];  -->  int noteDuration = 500/noteDurations[thisNote];

b. What song is playing? ;-)

Star Wars of course!

 

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?

I didn't really make any mistakes in the wiring. But later on, my unorganized wires were very stressful to navigate when the I trying to figure out why the LCD wasn't working.

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

Change line 48 to lcd.print("Cole Hoffer");

 

Part C. Fancy Inputs

1. Potentiometer

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

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

int sensorPin = A0; 

int sensorValue = 0;

int ledPin = 13;

 

void setup() {

  lcd.begin(16, 2);

  Serial.begin(9600); 

}

void loop() {

  lcd.setCursor(0, 0);

  lcd.print(millis()/1000);

  lcd.setCursor(0, 1);

  sensorValue = analogRead(sensorPin);

  Serial.println(sensorValue/4.06); 

  lcd.print(sensorValue/4.06);

  analogWrite(ledPin, sensorValue/4.06); 

}

 

The 4.06 allows for the sensor range to be from 0-255 (the leds range)

2. Flex Sensor

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

Flat = 12kOhms

Bent = 41kOhms

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

Vout = (R2 / (R1+R2)) * Vin

From straight to bent:

3.46v to 1.95v

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

The LED brightness change is lower than that of potentiometer, unless you divide the sensor value by a lower value, in order to gain the same brightness affect on the led.

d. Lowly Multimeter

#include <LiquidCrystal.h>

 

 

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

int sensorPin = A0;   

int sensorValue = 0;

 

void setup() {

   lcd.begin(16, 2);

 

}

 

void loop() {

   sensorValue = analogRead(sensorPin);    

   analogWrite(ledPin, sensorValue/2.79);  

   lcd.setCursor(0,0);

   lcd.print(sensorValue);

   lcd.setCursor(0,1);

   lcd.print("LED:");

   lcd.setCursor(6,1);

   lcd.print(sensorValue/2.79);

   delay(100);

 

}

 

 

     

 

3. Force Sensitive Resistor

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

61kOhms to 0.5kOhms 

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

Inverse, as force is increased, resistance decreases

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 sensorPin1 = A0;   

int sensorPin2 = A1;    

int ledPin = 13;      

int sensorValue1 = 0;

int sensorValue2 = 0;

 

void setup() {

   pinMode(ledPin, OUTPUT);  

   lcd.begin(16, 2);

 

}

 

void loop() {

 sensorValue1 = analogRead(sensorPin1);

   sensorValue2 = analogRead(sensorPin2); 

   lcd.setCursor(0,1);

   lcd.print(sensorValue1);

 

   lcd.setCursor(6,1);

   lcd.print(sensorValue2);

 

 

   if(sensorValue1>sensorValue2){

      lcd.setCursor(0,0);

      lcd.print("player 1 winning");

   }

   else if(sensorValue2>sensorValue1){

      lcd.setCursor(0,0);

      lcd.print("player 2 winning");

   }

   else{

     lcd.setCursor(0,0);

     lcd.print("tie, or error");

   }

}

 

 

Part D. Timer

 

 

 

 

 

 

 

 

Comments (0)

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