Part A
a. How would you change the code to make the song play twice as fast?
int noteDuration = 1000/noteDurations[thisNote] <- this line determines how fast the standard note is playing. To change the duration, divide this value by a factor, in this case, 2.
✔
b. What song is playing? ;-)
STAR WAR THEME!
✔
Part B
a. What voltage level do you need to power your display?
4.5 V
✔
b. What was one mistake you made when wiring up the display? How did you fix it?
Everything worked the first time~ :)
✔
c. What line of code do you need to change to make it flash your name instead of "Hello World"?
lcd.print("Yuhui Li");
✔
Part C
a1.
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);
Serial.begin(9600);
}
void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
analogWrite(ledPin,sensorValue/2.64); // 0-673 to 0-255
}
✔
2a. What resistance do you see with a Multimeter when the sensor is flat? When it is bent?
~11 kOhm when the sensor is flat. When its bent, depends on which way, the value either go up to ~30 kOhm and ~9 Kohm.
✔
2b. What kind of voltages should we expect for the Arduino analog pin based on the sensor resistance?
The analogRead from the flex sensor is from 350-500. So since Arduino change analogue 0-5V to 0-1023, the voltages are between ~1.7V to ~2.4V.
✔
2c. How does the range of the LED's brightness change compared to the potentiometer?
The range from the potentiometer is between 0-673, which is greater.
✔
2d. Include a copy of your Lowly Multimeter code in your lab write-up.
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);
//Serial.begin(9600);
}
void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
analogWrite(ledPin,(sensorValue-350)*1.7); // 350-500 to 0-255
}
✔
3a. What resistance values do you see from your force sensor?
0 to almost 1023
✔
3b. What kind of relationship does the resistance have as a function of force applied? (e.g., linear?)
It's a curve, at the beginning the resistance decreases quickly and as more and more pressure applied, the rate slows down
✔
3c. 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 ps1Pin = A0;
int ps2Pin = A1;
int i1 = 0;
int i2 = 0;
// the setup routine runs once when you press reset:
void setup() {
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("hello, world!");
pinMode(ps1Pin,INPUT);
pinMode(ps2Pin,INPUT);
Serial.begin(9600);
}
// the loop routine runs over and over again forever:
void loop() {
i1 = analogRead(ps1Pin);
i2 = analogRead(ps2Pin);
Serial.println(i1);
Serial.println(i2);
Serial.println(" ");
lcd.clear();
if (i1==i2){
lcd.print("Even");
}
else if (i1<i2){
lcd.print("Orange winning");
}
else {
lcd.print("Green winning"); //my wires are colour coded so green is for one of the buttons and orange is for another
}
delay(100);
}
✔
Comments (1)
xinyi xie said
at 8:06 pm on Jul 26, 2014
Great job!
You don't have permission to comment on this page.