The following is what we have so far for our projects code. We attempted to post the code through github but were having issues:
//LCD display
#include <LiquidCrystal.h> // Include the library to use a LCD display
#define sensor 0 // Define the A0 pin as “sensor”
int Vin; // Variable to read the value from the Arduino’s pin
float Temperature; // Variable that receives the converted voltage value to temperature
float TF; // Variable to receive the converted value from ºC to ºF
LiquidCrystal lcd (12, 11, 5, 4, 3, 2);
/* The function above declares which Arduino’s pins will be used for controlling the LCD */
//knock Sensor
int ledPin = 13;
int knockSensor = 0;
byte val = 0;
int statePin = LOW;
int THRESHOLD = 100;
void setup()
{
lcd.begin(16, 2); // It tells the Arduino that the display is a 16x2 type
lcd.print("Temperature: "); // Send the text to the screen of the display.
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop()
{{
Vin = analogRead (sensor); /* Tells the Arduino to read the pin and stores the value in “Vin” */
Temperature=(500*Vin)/1023; /* Converts the voltage value into temperature and stores it into the “Temperature” variable (in ºC)*/
TF = ((9*Temperature)/5)+32; // Converts ºC to ºF
lcd.setCursor(0, 1); // Moves the cursor of the display to the next line
lcd.print(TF); // Exhibits the value of the temperature on the display
lcd.print(" F"); // Writes “F” to indicate that it is in Fahrenheit scale.
delay(1000); // Waits for a second to read the pin again
}
val = analogRead(knockSensor);
if (val >= THRESHOLD) {
statePin = !statePin;
digitalWrite(ledPin, statePin);
Serial.println("Knock!");
}
delay(100); // we have to make a delay to avoid overloading the serial port
}
No comments:
Post a Comment