hello bit confused at why this does seem to be working. im using max to control the serial but the buttons on 13 and 7 dont seem to be working, any ideas why??
int ledPina = 11;
int ledPinb = 10;
int ledPinc = 9;
int ledPind = 6;
int op;
int vala;
int x;
void setup()
{
// begin the serial communication
Serial.begin(9600);
pinMode(ledPina, OUTPUT);
pinMode(ledPinb, OUTPUT);
pinMode(ledPinc, OUTPUT);
pinMode(ledPind, OUTPUT);
}
void loop()
{
if (Serial.available()) {
op = Serial.read();
if (op == 1) {
delay(5);
vala = Serial.read();
analogWrite(ledPina, vala);
}
if (op == 2) {
delay(5);
vala = Serial.read();
analogWrite(ledPinb, vala);
}
if (op == 3) {
delay(5);
vala = Serial.read();
analogWrite(ledPinc, vala);
}
if (op == 4) {
delay(5);
vala = Serial.read();
analogWrite(ledPind, vala);
}
if (op == 9) { // If an '4' is received then read the pins
for (int pin= 0; pin<=5; pin++){ // Read and send analog pins 0-5
x = analogRead(pin);
sendValue (x);
}
for (int pin= 2; pin<=13; pin++){ // Read and send digital
if (pin == 6){ pin++; }
else if (pin == 9){ pin++; }
else if (pin == 10){ pin++; }
else if (pin == 11){ pin++; }
else {
x = digitalRead(pin);
sendValue (x);
}
}
Serial.println(); // Send a carriage returnt to mark end of pin data.
delay (5); // add a delay to prevent crashing/overloading of the serial port
// dealt with with the metro, kept here for reference
}
}
}
void sendValue (int x){ // function to send the pin value followed by a "space".
Serial.print(x);
Serial.print(32, BYTE);
}