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

Report - Lab 3

Page history last edited by Benjamin Tee 11 years, 8 months ago

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

Change the 1.30 to 0.65 in the line: 

  int pauseBetweenNotes = noteDuration * 1.30;    

b. What song is playing? ;-)

     star wars theme song


 

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 miss two pins in the LCD, so to correct it I just recheck the connections and connect it again.

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

     lcd.print("Javier, Flores")


 

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

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

int ledPin = 9;      // 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);

  pinMode(sensorPin, INPUT);  

}

 

void loop() {

  // read the value from the sensor:

  sensorValue = analogRead(sensorPin);

  sensorValue = map(sensorValue, 0, 1025, 0, 255);  

  // turn the ledPin on

  analogWrite(ledPin, sensorValue);                  

}


 

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

     8.2 kOhms when flat

     7.8 kOhms when bent in

     19.0 kOhms when bent out

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

   Since I'm working with 3.3 V

       It will vary from 1.77 V to 2.44 V 

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

     The brightness change is in a smaller range (with the same code).

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

#include <LiquidCrystal.h>

 

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

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

float sensorValue = 0;

int sensorPin = 21;

 

void setup() {

  pinMode(sensorPin, INPUT);

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

  lcd.begin(16, 2);

}

 

void loop() {

  // set the cursor to column 0, line 1

  // (note: line 1 is the second row, since counting begins with 0):

  lcd.setCursor(0, 1);

  int sensorValue = analogRead(sensorPin);

  sensorValue = map(sensorValue, 0, 1025, 0, 1); 

  lcd.print(sensorValue * 3.3);

}


 

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

     The resistance decreases from infinite +(when no force is applied) to the 350 ohms.

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

     Logarithmic

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 sensorPin = A0;
int sensorValue = 0;

int sensorPin2 = A1;
int sensorValue2 = 0;


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

void loop() {

  // read the value from the sensor:

  sensorValue = analogRead(sensorPin);  

  sensorValue2 = analogRead(sensorPin2);

 

lcd.setCursor(0, 0);

  lcd.print(sensorValue, DEC); 

  lcd.print(" vs  ");
  lcd.print(sensorValue2, DEC); 

 


lcd.setCursor(0, 1);

  if (sensorValue<sensorValue2)
    lcd.print("Player 2 is winning!");
  else
      lcd.print("Player 1 is winning!");


  delay(500);
}

 

 


 

 

 

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

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

 

//code


#include "pitches.h"
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int sensorValue;
int intTime = 5;
int startTime = 0;
int sensorPin = A1;

void setup() {
   lcd.begin(16, 2);
   lcd.print("timer");
}

void loop() {
   sensorValue = analogRead(sensorPin);
   if (sensorValue > 500) {
      startTime = millis();
      while (1){
        int elapsed = (millis() - startTime)/1000;
        
        lcd.setCursor(0, 1);
        lcd.print(intTime - elapsed,DEC);
        if (intTime - elapsed < 1) {
          for (int i = 0 ; i < 3; i++){
            tone(8, 440, 200);
            delay(400);
          }
          break;
        }
      }
   }
}

 


 

 

 

Comments (0)

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