I'm building a simple EEPROM programmer that allows me to set individual bytes. The idea is to be able to enter an address on the serial monitor, then the data. I managed to cobble a sketch together which does not work properly. The sketch should take any number entered and turn it into a byte, then set 8 digital outputs (pin 2-9) with the individual bits. My only worry is that the sketch does set the first pin (pin 2) but the rest of them. I think the for loop is executed only once. What am I doing wrong?
char inData[10];
int index, i;
boolean started = false;
boolean ended = false;
int AP[8] = {
2,3,4,5,6,7,8,9};
int AD[8] = {
0,0,0,0,0,0,0,0};
void setup(){
Serial.begin(9600);
Serial.println("ready");
for (i=0;i<8;i++) {
pinMode(AP[i],OUTPUT);
}
// Setup Data Pins
for (i=0;i<8;i++) {
pinMode(AD[i],OUTPUT);
}
}
void loop()
{
while(Serial.available() > 0)
{
char aChar = Serial.read();
if(aChar == '>')
{
started = true;
index = 0;
inData[index] = '\0';
}
else if(aChar == '<')
{
ended = true;
}
else if(started)
{
inData[index] = aChar;
index++;
inData[index] = '\0';
}
}
if(started && ended){
int inInt = atoi(inData); // Convert the string to an integer
for(int j=0; j<8; j++){
int b = bitRead(inInt,j);
Serial.println(b);
if((b&bit(j))>0) {
AD[j]=HIGH;
}
else {
AD[j]=LOW;
}
digitalWrite(AP[j],AD[j]);
delay(100);
}
Serial.println(" ");
// Get ready for the next time
started = false;
ended = false;
index = 0;
inData[index] = '\0';
}
}