Sending Simple message between arduinos over digital pins

I've been trying to send simple high/low signals over digital pins for arduinos to communicate, this is just to confirm the receiving end code works before I install the arduino to recieve the same types of messages from an FRC roborio via DIO. The receiving end gets the proper messages from the sender and can print the "bits" to the serial monitor but for some reason none of the LEDs turn on or react to the change. I have confirmed that the LEDs work on the pins they are currently plugged into as well as any other hardware fault. Something in the IF statement is not registering the values of the input pins. Anyone have any ideas?

[code]
// (0, 0, 0)   (0, 0, 1) --> upcone  (0, 1, 0) --> downcone  (0, 1, 1) --> upcube
// (1, 0, 0) --> dwncbe  (1, 0, 1) --> autofd  (1 1, 0) --> prmve  (1, 1, 1) --> Fault

// fault is CAN/COMM or Brownout
//(bit3, bit2, bit1)

const int redPin = 9;
const int greenPin = 10;
const int bluePin = 11;

const int A = 4;
const int B = 6;
const int C = 7;

int rVal = 254;
int gVal = 1;
int bVal = 127;

int rDir = -1;
int gDir = 1;
int bDir = -1;

int bit1 = 0;
int bit2 = 0;
int bit3 = 0;

void coneUp(){
  setColor(255, 255, 0);
}

void coneLow(){
  setColor(255, 255, 0);
  delay(200);
  setColor(255, 255, 0);
  delay(200);

}

void cubeUp(){
  setColor(255, 0, 255);
}

void cubeLow(){
  setColor(255, 0, 255);
  delay(200);
  setColor(255, 0, 255);
  delay(200);

}

void fault(){
  setColor(255, 192, 203);
  delay(100);
  setColor(0, 0, 0);
  delay(100);
}


void presetMove(){
  setColor(0, 255, 0);
  delay(200);
  setColor(0, 0, 0);
  delay(200);
}


void autoFade(){
  analogWrite(redPin, rVal);
  analogWrite(greenPin, gVal);
  analogWrite(bluePin, bVal);

  // change the values of the LEDs
  rVal = rVal + rDir;
  gVal = gVal + gDir;
  bVal = bVal + bDir;

  // for each color, change direction if
  // you reached 0 or 255
  if (rVal >= 255 || rVal <= 0) {
    rDir = rDir * -1;
  }

  if (gVal >= 255 || gVal <= 0) {
    gDir = gDir * -1;
  }

  if (bVal >= 255 || bVal <= 0) {
    bDir = bDir * -1;
  }

  // slight delay so it doesn't rotate color too quicky
  delay(40);
}

void setColor(int R, int G, int B){
  analogWrite(redPin, R);
  analogWrite(greenPin, G);
  analogWrite(bluePin, B);
}


void setup() {
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT);
  pinMode(A, INPUT);
  pinMode(B, INPUT);
  pinMode(C, INPUT);
  
  Serial.begin(9600);
}

void loop(){
bit1 = digitalRead(A);
bit2 = digitalRead(B);
bit3 = digitalRead(C);
Serial.print(bit3);
Serial.print(bit2);
Serial.println(bit1);

  
    if (bit3 == 0 && bit2 == 0 && bit1 == 1) {
    coneUp;
    } else if (bit3 == 0 && bit2 == 1 && bit1 == 0) {
    coneLow;
    } else if (bit3 == 0 && bit2 == 1 && bit1 == 1) {
    cubeUp;
    } else if (bit3 == 1 && bit2 == 0 && bit1 == 0) {
    cubeLow;
    } else if (bit3 == 1 && bit2 == 0 && bit1 == 1) {
    autoFade;
    } else if (bit3 == 1 && bit2 == 1 && bit1 == 0) {
    presetMove;
    } else if (bit3 == 1 && bit2 == 1 && bit1 == 1) {
    fault;
    } else if (bit3 == 0 && bit2 == 0 && bit1 == 0) {
    setColor (0, 0, 0);
    }
  }


[/code]

The syntax to call a function uses parentheses and is as follows

if (bit3 == 0 && bit2 == 0 && bit1 == 1) {
    coneUp( );  
}

You make this mistake of not have parentheses in several locations.

1 Like

thank you so much!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.