Source Code-234
Source Code-234
Source Code-234
//
// FILE: dht11_test1.pde
// PURPOSE: DHT11 library test sketch for Arduino
//
#include <LiquidCrystal.h>
#include "notes.h"
//initialize the library with the numbers of the interface pins
LiquidCrystal lcd(3, 4, 5, 6, 7, 8);
int ledLow=A3;
int noteGood=A2;
int ledHigh=A1;
int tempMode;
int GUITAR_IN=A0;
int peaks = 0;
int sample[660];
float period = 0;
float frequency = 0;
float sampleTime = 0;
float startTime = 0;
float stopTime = 0;
#include "dht11.h"
dht11 DHT11;
#define DHT11PIN 2
void setup()
{
/*Serial.begin(9600);
Serial.print("SampleTime\tSamples\tPeriod\tFrequency\tPeaks\n");
Serial.begin(115200);
Serial.println(DHT11LIB_VERSION);
Serial.println();*/
lcd.begin(16,2); //sets the number of rows and columns for the LCD display
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Hello Tech 6100!");
delay(2000);
lcd.clear();
pinMode(GUITAR_IN, INPUT); //Set the PIN 28(A05) as and input
pinMode(noteGood, OUTPUT);
pinMode(ledLow, OUTPUT);
pinMode(ledHigh, OUTPUT);
}
void loop()
{
/*if(digitalRead(stringSelect==HIGH))
{
note++;
}*/
/******************************************************************
samples the input signal, finds it peak and finds the peaks of the
signal. This time determines period and then inverses that value to
determine frequency
*******************************************************************/
startTime=millis(); //start of sampling
for(int i=0; i<660; i++){ //takes 800 samples of the input
sample[i]=analogRead(GUITAR_IN); //read the guitar input
delay(1);
}
stopTime = millis(); //stop time in miliseconds
sampleTime = ((stopTime-startTime)); //the time it takes for all 800 samples is
equal to stop time-start time
for(int k=0; k<660; k++){
if ((sample[k]>sample[k-1]) & (sample[k]>sample[k+1])) //determines the number of
peaks after 800 samples
{
peaks++;
}
}
period = sampleTime/peaks;
frequency = 1000.0/period;
peaks=0;
int chk = DHT11.read(DHT11PIN);
/*Serial.print(sampleTime);
Serial.print("\t\t800\t");
Serial.print(period);
Serial.print("\t");
Serial.print(frequency);
Serial.print("\t");
Serial.print("\t");
Serial.print(peaks);
Serial.print("\n");*/
//peaks=0;
delay(500);
/***********************************************************
If else controlling lcd output and note good light. When the
frequency equals that of notes E,A,D,G,B,or E the green
tuning good indicator turns on
***********************************************************/
if((frequency >= (LowE-3)) && (frequency <=(LowE+3))){
digitalWrite(noteGood, HIGH);
}
else if((frequency >= (A-3)) && (frequency <=(A+3)))
{
digitalWrite(noteGood, HIGH);
}
else if((frequency >= (D-3)) && (frequency <=(D+3)))
{
digitalWrite(noteGood, HIGH);
}
else if((frequency >= 382) && (frequency <=389))
{
digitalWrite(noteGood, HIGH);
}
else if((frequency >= (B-3)) && (frequency <=(B+3)))
{
digitalWrite(noteGood, HIGH);
}
else if((frequency >= (HighE-3)) && (frequency <=(HighE+3)))
{
digitalWrite(noteGood, HIGH);
}
else
{
digitalWrite(noteGood, LOW);
}
/***********************************************************
If else controlling the tuning low indicator when approaching a note
************************************************************/
if((frequency >= (LowE-8)) && (frequency <(LowE-3))){
digitalWrite(ledLow, HIGH);
}
else if((frequency >= (A-8)) && (frequency <(A-3))){
digitalWrite(ledLow, HIGH);
}
else if((frequency >= (D-8)) && (frequency <(D-3))){
digitalWrite(ledLow, HIGH);
}
else if((frequency >= 375) && (frequency <382)){
digitalWrite(ledLow, HIGH);
}
else if((frequency >= (B-8)) && (frequency <(B-3))){
digitalWrite(ledLow, HIGH);
}
else if((frequency >= (HighE-8)) && (frequency <(HighE-3))){
digitalWrite(ledLow, HIGH);
}
else
{
digitalWrite(ledLow, LOW);
}
/***********************************************************
If else controlling the tuning high indicator when leaving
a notes boundries
***********************************************************/
if((frequency > (LowE+3)) && (frequency <=(LowE+8)))
{
digitalWrite(ledHigh, HIGH);
}
else if((frequency > (A+3)) && (frequency <=(A+8)))
{
digitalWrite(ledHigh, HIGH);
}
else if((frequency > (D+3)) && (frequency <=(D+8)))
{
digitalWrite(ledHigh, HIGH);
}
else if((frequency > 389) && (frequency < 400))
{
digitalWrite(ledHigh, HIGH);
}
else if((frequency > (B+3)) && (frequency <=(B+8)))
{
digitalWrite(ledHigh, HIGH);
}
else if((frequency > (HighE+3)) && (frequency <=(HighE+8)))
{
digitalWrite(ledHigh, HIGH);
}
else
{
digitalWrite(ledHigh, LOW);
}
/************************************************************
Sets the cursor and displays the temperature and humidity values
on the lcd display
*************************************************************/
//delay(2000);*/
/*else{
startTime=millis();
for(int i=0; i<800; i++){
sample[i]=analogRead(GUITAR_IN);
delay(1);
}
stopTime = millis();
sampleTime = ((stopTime-startTime));
for(int k=0; k<800; k++){
if ((sample[k]>sample[k-1]) & (sample[k]>sample[k+1]))
{
peaks++;
}
}
period = sampleTime/peaks;
frequency = 1000.0/period;
Serial.print(sampleTime);
Serial.print("\t\t800\t");
Serial.print(period);
Serial.print("\t");
Serial.print(frequency);
Serial.print("\t");
Serial.print("\t");
Serial.print(peaks);
Serial.print("\n");
peaks=0;*/
//
// END OF FILE
//