Hi everyone,
I was hoping I wouldn't be asking for help so quickly in to my project. Last week I didn't even know what an Arduino was, this week I have got this far but have an issue. I know my code is terrible, I hope that I can grow it as the months go on and fine tune it. However, I have hit a wall for the next step of my project.
I have an array called Byte that takes the EQ bands from sound and put them in 0 to 7 of the byte called Band. I would really like these to be a float so I can multiply them up to 4095 for my LEDs. I have looked for about 4 hours but have move ZERO paces forward. Can anyone help? Even just point me in the right direction?
Thank you in advance.
// ------------ ---u----
// ARDUINO 13|-> SCLK (pin 25) OUT1 |1 28| OUT channel 0
// 12| OUT2 |2 27|-> GND (VPRG)
// 11|-> SIN (pin 26) OUT3 |3 26|-> SIN (pin 11)
// 10|-> BLANK (pin 23) OUT4 |4 25|-> SCLK (pin 13)
// 9|-> XLAT (pin 24) . |5 24|-> XLAT (pin 9)
// 8| . |6 23|-> BLANK (pin 10)
// 7| . |7 22|-> GND
// 6| . |8 21|-> VCC (+5V)
// 5| . |9 20|-> 2K Resistor -> GND
// 4| . |10 19|-> +5V (DCPRG)
// 3|-> GSCLK (pin 18) . |11 18|-> GSCLK (pin 3)
// 2| . |12 17|-> SOUT
// 1| . |13 16|-> XERR
// 0| OUT14|14 15| OUT channel 15
// ------------ --------
//LCD Function LCD Pin Arduino
//VSS 1 GND
//VDD 2 +5V
//VO 3 10k – 20k Potentiometer
//RS 4 Pin 2
//RW 5 GND
//Enable 6 Pin 6
//D0 7 Not needed for 4-Bit
//D1 8 Not needed for 4-Bit
//D2 9 Not needed for 4-Bit
//D3 10 Not needed for 4-Bit
//D4 11 Pin 7
//D5 12 Pin 8
//D6 13 Pin 12
//D7 14 Pin 14 which is A0
//A (Backlight +) 15 +4.2V
//K (Backlight -) 16 GND
#include <Tlc5940.h>
#include <LiquidCrystal.h>
float SpectrumLeft[7];
float SpectrumRight[7];
byte Band; //this is what the shield spectrum reader uses when it reads each frequency and then plugs it into SpectrumLeft[]
LiquidCrystal lcd(2, 6, 7, 8, 12, 14); //create the lcd variable
void setup () {
//Spectrum Shield
pinMode(5, OUTPUT);
pinMode(4, OUTPUT);
//Spectrum Shield init and reset
digitalWrite(4,LOW); //pin 4 is strobe on shield
digitalWrite(5,HIGH); //pin 5 is RESET on the shield
digitalWrite(4,HIGH);
digitalWrite(4,LOW);
digitalWrite(5,LOW);
//LCD init + reset
// lcd.clear(); //clear the LCD during setup
// lcd.begin(16,4); //define the columns (16) and rows (4)
//init TLC chip + reset
Tlc.init(4095);
Tlc.clear();
Tlc.update();
//Serial init for troublehsooting of input data
Serial.begin(9600);
}
void loop () {
readSpectrum();
// writeLCD();
writeTLC();
}
//Write Spectrum Values to LCD screen
void writeLCD(){
lcd.setCursor(0,1); //move the cursor to the 2nd line
lcd.print(SpectrumLeft[0]); //print...
lcd.setCursor(0,2); //move the cursor to the 2nd line
lcd.print(SpectrumLeft[1]);
lcd.setCursor(3,1); //move the cursor to the 2nd line
lcd.print(SpectrumLeft[2]);
lcd.setCursor(3,2); //move the cursor to the 2nd line
lcd.print(SpectrumLeft[3]);
lcd.setCursor(6,1); //move the cursor to the 2nd line
lcd.print(SpectrumLeft[4]);
lcd.setCursor(6,2); //move the cursor to the 2nd line
lcd.print(SpectrumLeft[5]);
lcd.setCursor(9,1); //move the cursor to the 2nd line
lcd.print(SpectrumLeft[6]);
delay(250);
lcd.clear(); //clear LCD, since we are still on 2nd line...
}
//Read Spectrum Shield, put values in SpectrumLeft[BAND]
void readSpectrum() {
// Band 0 = Lowest Frequencies.
for(Band=0;Band <6; Band++){
SpectrumLeft[Band] = analogRead(0); //left
digitalWrite(4,HIGH); //Strobe pin on the shield
digitalWrite(4,LOW);
for(int i = 0; i < 6; i++)
//Drop value down, get rid of shit
if (SpectrumLeft[Band] < 19)
{
SpectrumLeft[Band] = 0;
}
Serial.println(SpectrumLeft[1]);
}
}
void writeTLC(){
Tlc.set(1, SpectrumLeft[0]*256);
Tlc.set(5, SpectrumLeft[2]*256);
Tlc.set(7, SpectrumLeft[4]*256);
Tlc.set(11, SpectrumLeft[5]*256);
//Tlc.set(5, SpectrumLeft[4]);
//Tlc.set(6, SpectrumLeft[5]);
Tlc.update();
}