DanielSpruill_Lab(3)


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

     

     Simply doubling the numbers on line 26 causes them to play twice as fast. Ex: int noteDurations[] = {
       8, 16, 16, 8,8,8,8,8 };

 

b. What song is playing? ;-)

     Star wars !

 

a. What voltage level do you need to power your display?

     4.5V

 

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

     There weren't any mistakes during the creation of this except a poor soldering job!

 

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

     To do this, you need to edit the string on line 50

 

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

     

     

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
int brightness=0;// the brightness
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
  brightness=sensorValue; //sets what the brightness is to what the pot reading is
  analogWrite(ledPin, brightness/4.0117);  //sets the brightness
 
                
}

 

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

 

8.7, 8.5-10.5

 

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

 

Vout=(24/(8.7+24))*3.3=2.422

 

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

 

there is a much smaller range of numbers on the flex sensor than the pot.

 

 

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

 

/*
  Analog Input
 Demonstrates analog input by reading an analog sensor on analog pin 0 and
 turning on and off a light emitting diode(LED)  connected to digital pin 13.
 The amount of time the LED will be on and off depends on
 the value obtained by analogRead().
 
 The circuit:
 * Potentiometer attached to analog input 0
 * center pin of the potentiometer to the analog pin
 * one side pin (either one) to ground
 * the other side pin to +5V
 * LED anode (long leg) attached to digital output 13
 * LED cathode (short leg) attached to ground
 
 * Note: because most Arduinos have a built-in LED attached
 to pin 13 on the board, the LED is optional.
 
 
 Created by David Cuartielles
 modified 30 Aug 2011
 By Tom Igoe
 
 This example code is in the public domain.
 
 http://arduino.cc/en/Tutorial/AnalogInput
 
 */
#include <LiquidCrystal.h>
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
int brightness=0;// the brightness
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
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);   
  // turn the ledPin on
  brightness=sensorValue/2; //sets what the brightness is to what the pot reading is
  analogWrite(ledPin, brightness);  //sets the brightness
  Serial.println(brightness);
  lcd.print(analogRead(sensorPin));
                
}

 

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

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

c. Include a copy of your FSR thumb wrestling code in your lab write-up.

/*
  Analog Input
 Demonstrates analog input by reading an analog sensor on analog pin 0 and
 turning on and off a light emitting diode(LED)  connected to digital pin 13.
 The amount of time the LED will be on and off depends on
 the value obtained by analogRead().
 
 The circuit:
 * Potentiometer attached to analog input 0
 * center pin of the potentiometer to the analog pin
 * one side pin (either one) to ground
 * the other side pin to +5V
 * LED anode (long leg) attached to digital output 13
 * LED cathode (short leg) attached to ground
 
 * Note: because most Arduinos have a built-in LED attached
 to pin 13 on the board, the LED is optional.
 
 
 Created by David Cuartielles
 modified 30 Aug 2011
 By Tom Igoe
 
 This example code is in the public domain.
 
 http://arduino.cc/en/Tutorial/AnalogInput
 
 */
#include <LiquidCrystal.h>
int sensorPin = A0;    // select the input pin for the potentiometer
int sensorPin2 =A1;
int ledPin = 13;      // select the pin for the LED
int sensorValue = 0;  // variable to store the value coming from the sensor
int val2;
int brightness=0;// the brightness
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
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);
  val2 = analogRead(sensorPin2);  
 
  // turn the ledPin on
  brightness=sensorValue/2; //sets what the brightness is to what the pot reading is
  analogWrite(ledPin, brightness);  //sets the brightness
  Serial.println(brightness);
  if(val2>sensorValue){
  lcd.println("Player two is losing");
  delay(4500);
  }
  if(sensorValue>val2){
    lcd.println("player2 is winning");
    delay(2000);
  }
  delay(10000);
lcd.clear(); 
}