- Sun Nov 13, 2011 4:34 pm
#135725
I cannot seem to get this to work. I am trying to get Pin 13 to turn on and off based on spectrum values.
ie. Pin ON <100
Pin Off >100
int analogPin = 0; // read from multiplexer using analog input 0
int strobePin = 4; // strobe is attached to digital pin 4
int resetPin = 5; // reset is attached to digital pin 5
int spectrumValue[7]; // to hold a2d values
int digitalpin1 = 13;
void setup()
{
Serial.begin(9600);
pinMode(analogPin, INPUT);
pinMode(strobePin, OUTPUT);
pinMode(resetPin, OUTPUT);
analogReference(DEFAULT);
//pinMode(digitalpin1, LOW);
digitalWrite(resetPin, LOW);
digitalWrite(strobePin, HIGH);
//digitalWrite(digitalpin1, HIGH);
}
void loop()
{
digitalWrite(resetPin, HIGH);
digitalWrite(resetPin, LOW);
for (int i = 0; i < 7; i++) //i is equal to 0, if i is less than 7(bands from analog pin0) repeat loop until it equals 7.
{
digitalWrite(strobePin, LOW);
delayMicroseconds(30); // to allow the output to settle
spectrumValue = analogRead(analogPin);
// comment out/remove the serial stuff to go faster
// - its just here for show
if (spectrumValue < 10)
{
Serial.print(" ");
Serial.print(spectrumValue);
//digitalWrite(13, HIGH);
}
else if (spectrumValue < 100 )
{
Serial.print(" ");
Serial.print(spectrumValue);
digitalWrite(digitalpin1, HIGH);
}
else if (spectrumValue > 100 )
{
digitalWrite(digitalpin1, LOW);
}
else
{
Serial.print(" ");
Serial.print(spectrumValue);
//digitalWrite(digitalpin1, HIGH);
}
//digitalWrite(digitalpin1, HIGH);
digitalWrite(strobePin, HIGH);
}
Serial.println();
}