Compiling the following code, the case structure produces this error message for each line and finally -
status 1
Compilation error: cannot convert '' to 'int' in assignment
I'm a newby with C++ and haven't managed to understand arrays. It's part of a sketch for a mecanum wheel car using the Adafruit Motor Shield v2 on a Uno R3. The wheel array independently sets the direction of rotation of each wheel for various compass directions of travel.
These lines are from Monitor_Input.ino to receive an integer typed into the IDE monitor.
recvWithEndMarker();
showNewNumber();
if (dataNumber != 0)
LF, RR etc are abbreviations for left-front, right-rear wheel motors.
// Adafruit Motor Shield
#include <Adafruit_MotorShield.h>
#include <C:\Users\feral\Documents\Arduino\Monitor_Input\Monitor_Input.ino>
// Create the motor shield object with the default I2C address
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
Adafruit_DCMotor *motRF = AFMS.getMotor(1);
Adafruit_DCMotor *motRR = AFMS.getMotor(2);
Adafruit_DCMotor *motLR = AFMS.getMotor(3);
Adafruit_DCMotor *motLF = AFMS.getMotor(4);
int speed[4] = {80, 120, 80, 120}; // 0 <= n <= 255
int wheel[4] = {1, 1, 1, 1}; // stop (0), fore (1), rev (2)
int dir = 1; // compass directions, 0 to 15 cw & rot
void setup() {
Serial.begin(9600); // Set up Serial library at 9600 bps
AFMS.begin(1000); // PWM Frequency 1.0KHz
}
void loop() {
recvWithEndMarker();
showNewNumber();
if (dataNumber != 0){
dir = dataNumber;
switch (dir) {
case 1: wheel[4] = {1, 1, 1, 1}; break; // N
case 2: wheel[4] = {1, 1, 1, 1}; break; // NNE
case 3: wheel[4] = {0, 1, 0, 1}; break; // NE
case 4: wheel[4] = {2, 1, 2, 1}; break; // ENE
case 5: wheel[4] = {2, 1, 2, 1}; break; // E
case 6: wheel[4] = {2, 1, 2, 1}; break; // ESE
case 7: wheel[4] = {2, 0, 2, 0}; break; // SE
case 8: wheel[4] = {2, 2, 2, 2}; break; // SSE
case 9: wheel[4] = {2, 2, 2, 2}; break; // S
case 10: wheel[4] = {2, 2, 2, 2}; break; // SWS
case 11: wheel[4] = {0, 2, 0, 2}; break; // SW
case 12: wheel[4] = {1, 2, 1, 2}; break; // WSW
case 13: wheel[4] = {1, 2, 1, 2}; break; // W
case 14: wheel[4] = {1, 2, 1, 2}; break; // WNW
case 15: wheel[4] = {1, 0, 1, 0}; break; // NW
case 16: wheel[4] = {1, 1, 1, 1}; break; // NWN
case 17: wheel[4] = {2, 2, 1, 1}; break; // CW
case 18: wheel[4] = {1, 1, 2, 2}; break; // CCW
default: Serial.print("Case n is corrupt"); break;
}
}
motLFgo();
motLRgo();
motRRgo();
motRFgo();
}
// ===============================
void motLFgo() {
motLF ->setSpeed(speed[0]);
motLF ->run(wheel[0]);}
void motLRgo() {
motLR ->setSpeed(speed[1]);
motLR ->run(wheel[1]);}
void motRRgo() {
motRR ->setSpeed(speed[2]);
motRR ->run(wheel[2]);}
void motRFgo() {
motRF ->setSpeed(speed[3]);
motRF ->run(wheel[3]);}