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

RichardTiutiun_Lab3

Page history last edited by Richard Tiutiun 10 years, 8 months ago Saved with comment

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

int noteDuration = 500/noteDurations[thisNote];

b. What song is playing? ;-)

Luke Skywalker theme from Star Wars :)

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

I wired ground directly to pin 1. So when I needed to wire ground to pin 5, I had to either wire pins 1 and 5 together or use the second ground pin on the Arduino. Instead, I wired ground to a "blank" row of pins on the breadboard, then connected pins 1 and 5 to that row. 

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

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

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

int ledPin = 9;

 

int fadeAmount = analogRead(sensorPin);

int i = map(fadeAmount, 450, 470, 0, 255);

analogWrite(ledPin, i); 

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

Flat - 12.5 KOhm

Bent - 19 KOhm

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

//I used a 10 KOhm resistor instead of a 24 KOhm

(10k*3.3)/(12.5+10)k = 1.47 V

(10k*3.3)/(19+10)k = 1.14 V

vOut: 1.14-1.47 V

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

It's more sensitive, not as linear/stable. When the delay is included in the Lowly Multimeter, it is not as responsive.

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

int ledPin = 9;

 

void setup() {

  lcd.begin(16, 2);

  pinMode(ledPin, OUTPUT);  

}

 

void loop() {

  int fadeAmount = analogRead(sensorPin);

  int i = map(fadeAmount, 450, 470, 0, 255);

  analogWrite(ledPin, i);

  lcd.print(i);

  delay(300);

  lcd.clear();

}

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

When not press, it's off-the-charts in the mega-ohms, when pressed goes down to kilo-ohms.

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

Exponential.

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

 

const int sensorOne = A0;    // select the input pin for the first FSR

const int sensorTwo = A2;    // select the input pin for the second FSR

 

void setup() {

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

  lcd.begin(16, 2);

}

 

void loop() {

 

  int sensorOneValue = analogRead(sensorOne);

  int sensorTwoValue = analogRead(sensorTwo);

  String winnerOne = "";

  String winnerTwo = "";  

 

  if (sensorOneValue > sensorTwoValue)

    winnerOne = " winner";

  else if (sensorTwoValue > sensorOneValue)

    winnerTwo = " winner"; 

 

  lcd.setCursor(0, 0);

  lcd.print(sensorOneValue + winnerOne);

  lcd.setCursor(0, 1);

  lcd.print(sensorTwoValue + winnerTwo);

 

  lcd.clear();

}

 

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

LINK: http://www.youtube.com/watch?v=ChDHpn9MEhI&feature=youtu.be

 

Timer Code:

// include the library code:

#include <LiquidCrystal.h>

#include "pitches.h"

 

// notes in the melody:

int melody[] = { NOTE_C4, NOTE_G3,NOTE_G3, NOTE_A3, NOTE_G3,0, NOTE_B3, NOTE_C4 };

 

// note durations: 4 = quarter note, 8 = eighth note, etc.:

int noteDurations[] = { 4, 8, 8, 4,4,4,4,4 };

 

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

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

 

const int sensorPin = A0;    // select the input pin for the FSR

int sensorValue = 0;

 

const int increaseButton = 6;     // the number of the increase button pin

const int decreaseButton = 7;     // the number of the decrease button pin

int increaseButtonState;

int decreaseButtonState;

 

int time = 0;

 

void setTimer() {

  time = 0;

 

  lcd.print("Set Timer:");

  lcd.setCursor(0, 1);

 

  while (analogRead(sensorPin) < 650){    

    increaseButtonState = digitalRead(increaseButton);

    decreaseButtonState = digitalRead(decreaseButton);

 

    if (increaseButtonState != decreaseButtonState){

     if (increaseButtonState == HIGH){

         time += 1000;

     }

     else{

       if (time > 0)

         time -= 1000;

     }

    }

    lcd.setCursor(0, 1);

    lcd.print(time/1000);

    delay(150);

  }

 

  lcd.clear();

  lcd.print("Countdown:");

  lcd.setCursor(0, 1);

}

 

void setup() {

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

  lcd.begin(16, 2);

 

  pinMode(increaseButton, INPUT);     

  pinMode(decreaseButton, INPUT);     

 

  setTimer();

}

 

void loop() {

  lcd.setCursor(0, 1);

  lcd.print(time/1000);

  delay(1000);

  time -= 1000;

  if (time <= 0){

    lcd.clear();

    lcd.print("Reset");

 

    // iterate over the notes of the melody:

    for (int thisNote = 0; thisNote < 8; thisNote++) {

 

      // to calculate the note duration, take one second 

      // divided by the note type.

      //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.

      int noteDuration = 1000/noteDurations[thisNote];

      tone(8, melody[thisNote],noteDuration);

 

      // to distinguish the notes, set a minimum time between them.

      // the note's duration + 30% seems to work well:

      int pauseBetweenNotes = noteDuration * 1.30;

      delay(pauseBetweenNotes);

      // stop the tone playing:

      noTone(8);

    }

 

    lcd.clear();

    setTimer();

  }

}

 

-2 Where's the rest of the type up? :/ Video?

 

Comments (1)

Vivien Tsao said

at 11:39 pm on Jul 28, 2013

Good job overall

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