Lab 3
EE 47
John “Ian” Kelly
Got sick for 1.5 weeks, thus this may have been posted a bit late. David said this was okay.
Part A
int noteDuration = 2000/noteDurations[thisNote];
Part B
4.5 V but 5v is okay.
PART C
1. potentiometer
a.
int sensorPin = A0; // select the input pin for the potentiometer
int ledPin = 10; // 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
//divided by 3 because light faded fully 3 times with one turn of
// pot which meant analogRead value was 3x too big.
analogWrite(ledPin, sensorValue/3);
// stop the program for <sensorValue> milliseconds:
delay(10);
}
#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 = 10; // 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)*2;
// turn the ledPin on
lcd.setCursor(0,0);
analogWrite(ledPin, sensorValue);
lcd.print(sensorValue);
// stop the program for <sensorValue> milliseconds:
delay(0);
}
a. from 200k to .4 ohms.
b. it is inverse logarithmic. ie the more force the smaller the resistance. but applying force from 10k to 1k ohms is way easer than from 10 to 1 ohm.
c. thumb wrestle code:
// 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 sensorPin = A0; // select the input pin for the potentiometer
int FsensorPin = A1;
int sensorValue = 0; // variable to store the value coming from the sensor
int FsensorValue = 0;
void setup() {
// declare the ledPin as an OUTPUT:
lcd.begin(16,2);
}
void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
FsensorValue = analogRead(FsensorPin);
// turn the ledPin on
lcd.setCursor(0,0);
// analogWrite(ledPin, sensorValue);
lcd.print(sensorValue);
// stop the program for <sensorValue> milliseconds:
lcd.setCursor(0,1);
lcd.print(FsensorValue);
lcd.setCursor(4,1);
lcd.print("winner: ");
lcd.setCursor(12,1);
if(sensorValue > FsensorValue) {
lcd.print("A0");
}
else {
lcd.print("A1");
}
delay(0);
}
Part D timer