mercredi 30 septembre 2020

expected primary-expression before 'switch'

#include <IRremote.h>
#include <AFMotor.h>
#include <Servo.h>
int receiver = A5;

IRrecv irrecv(receiver);
decode_results results;

void translateIR(){
  switch(results.value){
    case 0xFFA25D: Serial.println("POWER");break;
    case 0xFFE21D: Serial.println("FUNCTION/STOP");break;
    case 0xFF629D: Serial.println("VOL+");break;
    case 0xFF22DD: Serial.println("FAST BACK");break;
    case 0xFF02FD: Serial.println("PAUSE");break;
    case 0xFFC23D: Serial.println("FAST FORWARD");break;
    case 0xFFE01F: Serial.println("DOWN");break;
    case 0xFFA857: Serial.println("VOL-");break;
    case 0xFF906F: Serial.println("UP");break;
    case 0xFF9867: Serial.println("EQ");break;
    case 0xFFB04F: Serial.println("ST/REPT");break;
    case 0xFF6897: Serial.println("0");break;
    case 0xFF30CF: Serial.println("1");break;
    case 0xFF18E7: Serial.println("2");break;
    case 0xFF7A85: Serial.println("3");break;
    case 0xFF10EF: Serial.println("4");break;
    case 0xFF38C7: Serial.println("5");break;
    case 0xFF5AA5: Serial.println("6");break;
    case 0xFF42BD: Serial.println("7");break;
    case 0xFF4AB5: Serial.println("8");break;
    case 0xFF52AD: Serial.println("9");break;
    case 0xFFFFFFF: Serial.println(" REPEAT");break;

    default:
      Serial.println(" other button");
  }
      delay(500);
  
}

AF_DCMotor Motor(1);
Servo servo1;
Servo servo2;

void setup(){
  if (irrecv.decode(&results)){
    translateIR();
    irrecv.resume();
  }

  
  Serial.begin(9600);
  servo1.attach(9);
  Motor.setSpeed(200);
  Motor.run(RELEASE);

}
void loop(){
  if (switch(results.value)) = (case 0xFF906F:){     // THE OTHER PROBLEM <-------------
    Motor.run(FORWARD);
  }
  else switch(results.value) != (case 0xFF906F:){    // THE PROBLEM <-------------
    Motor.run(RELEASE);
  } 
  
  
}

The problem is the if and else switch lines, The else switch line was, "else if switch(results.value) != (case 0xFF906F:){" but I changed it to "else". I need help I'm relatively new. What I am trying to do in the code is making it so if the receiver revives the information "case 0xFF906F:" then it performs and action with a motor, if the button is not being pressed anymore on the remote then the motor stops.

Aucun commentaire:

Enregistrer un commentaire