2-Button serial logic

I am trying to get a arduino mini to send serial massage a b c or d depinding on the state of three Buttons.
a for no Buttons pushed.
b for Button 1 pushed.
c for Button 2 pushed
d for when Button 1 and 2 are pushed.

Here's the Code i am using for the receiving arduino UNO

int button1State = 0;
const int button1 = 2;
int command = 0;

void setup() {     
const int button1 = 2;


Serial.begin(9600);	// opens serial port, sets data rate to 9600 bps

pinMode(0,INPUT);
pinMode(13,OUTPUT);
pinMode(3,OUTPUT); 
pinMode(12,OUTPUT);
pinMode(11,OUTPUT); 
pinMode(button1, INPUT);


}

void loop() {
    
  command = Serial.read();

  button1State = digitalRead(button1);
  
    if (command == 'a') {     
    // turn LED on:    
digitalWrite(12,0); //start motor-B
analogWrite(11,255);

digitalWrite(13,0);  //stop motor-A
analogWrite(3,0);

  }
  
      if (command == 'b') {     
        digitalWrite(12,0); //start motor-B
analogWrite(11,0);

digitalWrite(13,0);  //stop motor-A
analogWrite(3,255);
      }

      if (command == 'c') {     
digitalWrite(12,0); //start motor-B
analogWrite(11,0);

digitalWrite(13,0);  //stop motor-A
analogWrite(3,0);


if (command == 'd') {    
  
digitalWrite(12,0); //start motor-B
analogWrite(11,0);

digitalWrite(13,0);  //stop motor-A
analogWrite(3,0);
  }   
  
}

}

Great. Is there a question?

legoaceking:
I am trying to get a arduino mini to send serial massage to an arduino UNO a b c or d depinding on the state of three Buttons.
a for no Buttons pushed.
b for Button 1 pushed.
c for Button 2 pushed
d for when Button 1 and 2 are pushed.

that was the code for the arduino UNO not the mini.

I know. So is your question 'will you write my code for me?'

What have you got so far?

dxw00d:
I know. So is your question 'will you write my code for me?'

What have you got so far?

The question is How can I pull this off.

The question is How can I pull this off.

Read the state of the 1st switch.
Read the state of the 2nd switch.
If neither state is pressed (whatever that means for how the switches are wired), send 'a'.
Else, if both are pressed, send 'd'.
Else, if only one is pressed, send 'b' or 'c', depending on which one is pressed.

PaulS:

The question is How can I pull this off.

Read the state of the 1st switch.
Read the state of the 2nd switch.
If neither state is pressed (whatever that means for how the switches are wired), send 'a'.
Else, if both are pressed, send 'd'.
Else, if only one is pressed, send 'b' or 'c', depending on which one is pressed.

this is what i got so far.

const int buttonPin1 = 10;
const int buttonPin2 = 11;
    

int buttonState = 0;        

void setup() {

  pinMode(ledPin, OUTPUT);      

  pinMode(buttonPin1, INPUT);

  pinMode(buttonPin2, INPUT);    
}

void loop(){

  buttonState = digitalRead(button1);

  buttonState = digitalRead(button2);


  if (buttonState == HIGH) {    
    // turn LED on:    
    Serial.write((const uint8_t *)"d",1);  
  }
  else {
    // turn LED off:
    Serial.write((const uint8_t *)"a",1);
  }
}

How about this?

const int button1 = 10;
const int button2 = 11;
    

int buttonState = 0;        

void setup() {


  pinMode(button1, INPUT);

  pinMode(button2, INPUT);    
}

void loop(){

  buttonState = digitalRead(button1);

  buttonState = digitalRead(button2);


  if (button1 == HIGH) button2 == HIGH; {    
  
    Serial.write((const uint8_t *)"d",1);  
  }
  
  if (button1 == LOW) button2 == LOW; {    

    Serial.write((const uint8_t *)"a",1);  
  }
  
  
  if (button1 == HIGH) button2 == LOW; {    

    Serial.write((const uint8_t *)"b",1);  
  }
  
  if (button1 == LOW) button2 == HIGH; {    

    Serial.write((const uint8_t *)"c",1);  
  }
  
  
}

buttonState = digitalRead(button1);

buttonState = digitalRead(button2);

I'd like you to meet my brother, Al, and my other brother, Al.

You read two pins, and store the result in one variable. How will you know which switch was pressed?

  if (button1 == HIGH) button2 == HIGH; {    
  
    Serial.write((const uint8_t *)"d",1);  
  }

The syntax is wrong, for one thing. For another, the button1 value is a pin number. It will never be HIGH or LOW. Not if you expect to do serial output, anyway. The state obtained using digitalRead() will be.

const int button1 = 10;
const int button2 = 11;
    

int button1State = 0;        
int button2State = 0;

void setup() {


  pinMode(button1, INPUT);

  pinMode(button2, INPUT);    
}



void loop(){

  button1State = digitalRead(button1);
button2State = digitalRead(button2);
  
  if (button1State == HIGH) button2State == HIGH; {    
  
    Serial.write((const uint8_t *)"d",1);  
  }
  
  if (button1State == LOW) button2State == LOW; {    

    Serial.write((const uint8_t *)"a",1);  
  }
  
  
  if (button1State == HIGH) button2State == LOW; {    

    Serial.write((const uint8_t *)"b",1);  
  }
  
  if (button1State == LOW) button2State == HIGH; {    

    Serial.write((const uint8_t *)"c",1);  
  }
  
  delay(100);
  
}
  if (button1State == HIGH) button2State == HIGH; {    
  
    Serial.write((const uint8_t *)"d",1);  
  }

Still won’t compile.

  if (button1State == HIGH && button2State == HIGH)
  { 
    Serial.print("d");  
  }
const int button1 = 10;
const int button2 = 11;
    

int button1State = 0;        
int button2State = 0;

void setup() {


  pinMode(button1, INPUT);

  pinMode(button2, INPUT);    
}



void loop(){

  button1State = digitalRead(button1);
button2State = digitalRead(button2);
  
  if (button1State == HIGH && button2State == HIGH)
  {    
  
    Serial.print("d");  
  }
  
  if (button1State == LOW && button2State == LOW)
  {    

    Serial.print("a");  
  }
  
  
  if (button1State == HIGH && button2State == LOW)
  {    

    Serial.print("b");  
  }
  
  if (button1State == LOW && button2State == HIGH)
  {    

    Serial.print("c");  
  }
  
  delay(100);
  
}

Did you compile that? Did you test it? Does it do what you want?

Are you aware that the 4 if tests are exclusive? As soon as one is true, the rest must be false. So, make the last 3 else if, not if.

Did you compile that? Did you test it? Does it do what you want?

yes i did all that but it dose not send abc or d.

const int button1 = 10;
const int button2 = 11;

int button1State = 0;
int button2State = 0;

void setup() {

pinMode(button1, INPUT);

pinMode(button2, INPUT);
}

void loop(){

button1State = digitalRead(button1);
button2State = digitalRead(button2);

if (button1State == HIGH && button2State == HIGH)
{

Serial.print("d");
}

else if (button1State == LOW && button2State == LOW)
{

Serial.print("a");
}

else if (button1State == HIGH && button2State == LOW)
{

Serial.print("b");
}

else if (button1State == LOW && button2State == HIGH)
{

Serial.print("c");
}

delay(100);

}

If you just want to report the state of the buttons, how about:

char message_char(int button1,int button2)
{  return 'a' + digitalRead(button1) + (digitalRead(button2) << 1);
}

which will return
‘a’ if no buttons are pressed
‘b’ if button 1 is pressed,
‘c’ if button 2 is pressed, and
‘d’ if buttons 1 and 2 are both pressed.

yes i did all that but it dose not send abc or d.

Then you have a hardware problem. You are not using the internal pullup resistors, so you must have external resistors. Do you? How are the switches wired? Post a picture that CLEARLY shows how they are wired.

Where is the serial data supposed to go?

Correct me if im wrong, but don't you need to initialize the serial interface first?

calling the Serial.begin(9600); in the setup.

Correct me if im wrong, but don’t you need to initialize the serial interface first?

Oh sure. Come in at the end, and point out something that should have been obvious to everyone from the beginning. Make us all feel like losers.