I got an intresting probleam.
The code below works fine. When a pin pulls high the corect byte is sent. However these are not the bytes i want to be sending. When i change the command array to look like this byte commands[] = {0x00, 0x01}; the arduino goes nuts. Pin 13 starts blinking and the serial port stas dumping out 0x0d or 0xd0 i cant rember. if i pull the pins high I will see 0x00 or 0x01 but the garbage is undesirable. In the end i hope to have around 10 inputs and sending a serial command for each one. Any ideas?
int inputPins[] = {2,3};
byte commands[] = {0x41, 0x42};
int totalPins;
int ledPin = 13;
int delayTime = 250;
void setup(){
totalPins = sizeof(inputPins);
for(int n = 0; n < totalPins; n++){
pinMode(inputPins[n], INPUT);
}
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop(){
for(int n = 0; n < totalPins; n ++){
if(digitalRead(inputPins[n]) == HIGH){
blink();
Serial.write(commands[n]);
delay(delayTime);
}
delay(10);
}
}
void blink(){
digitalWrite(ledPin, HIGH);
delay(100);
digitalWrite(ledPin, LOW);
}