How would you change the code to make the song play twice as fast?
int noteDuration = 1000/noteDurations[thisNote];
To play twice as fast I can reduce 1000 to 500
int pauseBetweenNotes = noteDuration * 1.30;
I can also play with the pause between each notes by reducing the factor of 1.3.
What song is playing? ;-)
STARWARS!
Part B. Writing to the LCD
What voltage level do you need to power your display? Around 5V
b. What was one mistake you made when wiring up the display? How did you fix it? When I am soldering the headers to the LCD, one of the pins did not make a good electrical contact with the the LCD. i use the mulitmeter to check for short-circuit between each header and the the LCD. And I resolder the one to make a good electrical contact with the LCD.
c. What line of code do you need to change to make it flash your name instead of "Hello World"?
lcd.print("Kai Yu Tan!");
Potentiometer
Post a copy of your new code in your lab writeup.
int sensorPin = A0; // 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);
}
void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
// turn the ledPin on
analogWrite(ledPin, sensorValue*5/3);
}
Flex Sensor
What resistance do you see with a Multimeter when the sensor is flat? When it is bent?
Flat=9k ohms
Bent=80k ohms
What kind of voltages should we expect for the Arduino analog pin based on the sensor resistance?
From 7.6V to 24V
How does the range of the LED's brightness change compared to the potentiometer?
Comparatively smaller range
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);
int sensorPin = A0; // 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);
lcd.begin(16, 2);
}
void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
float voltage= sensorValue * (5.0 / 1024.0);
// Print the voltage value to the LCD.
lcd.setCursor(8, 1);
lcd.print(voltage);
// turn the ledPin on
analogWrite(ledPin, sensorValue*5/3);
// stop the program for <sensorValue> milliseconds:
delay(25);
}
Force Sensitive Resistor
What resistance values do you see from your force sensor?
0.2k to 100kohms
b. What kind of relationship does the resistance have as a function of force applied? (e.g., linear?)
resistance has a power law relationship with the force applied but will deviate at higher force range.
Include a copy of your FSR thumb wrestling 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);
int sensorPin1 = A0;
int sensorPin2 = A1;// select the input pin for the potentiometer
int ledPin = 9; // select the pin for the LED
int sensorValue1 = 0; // variable to store the value coming from the sensor
int sensorValue2 = 0; // variable to store the value coming from the sensor
void setup() {
// declare the ledPin as an OUTPUT:
pinMode(ledPin, OUTPUT);
lcd.begin(16, 2);
}
void loop() {
// read the value from the sensor:
sensorValue1 = analogRead(sensorPin1);
sensorValue2 = analogRead(sensorPin2);
// Compare results
if (sensorValue1>sensorValue2) {
lcd.setCursor(8, 1);
lcd.print("FSR 2 WINS");
}
if (sensorValue2>sensorValue1) {
lcd.setCursor(8, 1);
lcd.print("FSR 1 WINS");
}
if (sensorValue2==sensorValue1) {
lcd.setCursor(8, 1);
lcd.print("TIE");
}
}
Part D. Timer
a. Make a short video showing how your timer works, and what happens when time is up!
b. Post a link to theLab 3 Timers Hall of Fame.