Hey guys,
Today I switched from my UNO to DUE because I needed more I/O. (only larger board on my school)
So when I plugged it all in I noticed my motor leds are on and cant use the joystick anymore.
Also my motor is turning.
When I delete the joystick code, and upload without it, the leds are off and my motor is not turning.
Is there something different with coding between these two boards?
My code is a bit of a mess, sorry.
const int vert_motor1 = 2; //pin 2 of arduino to pin 7 of l293d
const int vert_motor2 = 3; //pin 3 of arduino to pin 2 of l293d
const int horz_motor1 = 7; //pin 7 of arduino to pin 10 of l293d
const int horz_motor2 = 8; //pin 8 of arduino to pin 15 of l293d
const int mvert = 9;
const int mhorz = 10;
int joyvert = A0;
int joyhorz = A1;
int vert_motor_led = 6;
int horz_motor_led = 4;
int modeSwitchPin = 13; // switch is connected to pin 13
int ledAutoPin = 11;
int ledManPin = 12;
int val; // variable for reading the pin status
int val2; // variable for reading the delayed status
int modeButtonState; // variable to hold the button state
int Mode = 0;
int start_stop_auto = 5;
int val3;
int val4;
int startButtonState;
int state = 0;
const unsigned int onTime = 1000;
const unsigned int offTime = 500;
unsigned long previousMillis = 0;
int interval = onTime;
boolean motorstate1 = true;
boolean motorstate2 = false;
int speed_vert = 0;
int speed_horz = 0;
int joyposvert = 512;
int joyposhorz = 512;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(vert_motor1, OUTPUT);
pinMode(vert_motor2, OUTPUT);
pinMode(horz_motor1, OUTPUT);
pinMode(horz_motor2, OUTPUT);
pinMode(mvert, OUTPUT);
pinMode(mhorz, OUTPUT);
pinMode(vert_motor_led, OUTPUT);
pinMode(horz_motor_led, OUTPUT);
pinMode(modeSwitchPin, INPUT); // Set the switch pin as input
pinMode(start_stop_auto, INPUT_PULLUP);
pinMode(ledAutoPin, OUTPUT);
pinMode(ledManPin, OUTPUT);
previousMillis = millis();
modeButtonState = digitalRead(modeSwitchPin); // read the initial state
}
void loop() {
//***AUTO/MANUAL SWITCH LOOP***//
unsigned long currentMillis = millis();
val = digitalRead(modeSwitchPin); // read input value and store it in val
delay(10); // 10 milliseconds is a good amount of time
val2 = digitalRead(modeSwitchPin); // read the input again to check for bounces
if (val == val2) { // make sure we got 2 consistant readings!
if (val != modeButtonState) { // the button state has changed!
if (val == LOW) { // check if the button is pressed
if (Mode == 0) {
Mode = 1;
} else {
if (Mode == 1) {
Mode = 0;
}
}
}
}
}
modeButtonState = val; // save the new state in our variable
joyposvert = analogRead(joyvert);
joyposhorz = analogRead(joyhorz);
if (Mode == 0)
{
digitalWrite(ledAutoPin, HIGH);
digitalWrite(ledManPin, LOW);
Serial.println("Automatic Mode");
val3 = digitalRead(start_stop_auto); // read input value and store it in val
delay(10); // 10 milliseconds is a good amount of time
val4 = digitalRead(start_stop_auto); // read the input again to check for bounces
if (val3 == val4) { // make sure we got 2 consistant readings!
if (val3 != startButtonState) { // the button state has changed!
if (val3 == LOW) { // check if the button is pressed
if (state == 0) {
state = 1;
} else {
if (state == 1) {
state = 0;
}
}
}
}
}
startButtonState = val3; // save the new state in our variable
if (state == 0) { // all-off
Serial.println("Stop automatisch programma");
digitalWrite(vert_motor_led, LOW);
digitalWrite(horz_motor_led, LOW);
digitalWrite(vert_motor1, LOW);
digitalWrite(vert_motor2, LOW);
digitalWrite(horz_motor1, LOW);
digitalWrite(horz_motor2, LOW);
analogWrite(mvert, 0);
analogWrite(mhorz, 0);
}
if (state == 1) {
Serial.println("Start automatisch programma");
previousMillis = currentMillis;
}
}
}
if (Mode == 1)
{
digitalWrite(ledAutoPin, LOW);
digitalWrite(ledManPin, HIGH);
digitalWrite(vert_motor_led, LOW);
digitalWrite(horz_motor_led, LOW);
Serial.println("MANUAL MODE");
if (joyposvert < 470)
{
digitalWrite(vert_motor1, LOW);
digitalWrite(vert_motor2, HIGH);
digitalWrite(vert_motor_led, HIGH);
speed_vert = map(joyposvert, 470, 0, 0, 255);
}
else if (joyposvert > 550)
{
digitalWrite(vert_motor1, HIGH);
digitalWrite(vert_motor2, LOW);
digitalWrite(vert_motor_led, HIGH);
speed_vert = map(joyposvert, 550, 1023, 0, 255);
}
else
{
speed_vert = 0;
speed_horz = 0;
digitalWrite(vert_motor_led, LOW);
digitalWrite(horz_motor_led, LOW);
}
if (joyposhorz < 470)
{
digitalWrite(horz_motor1, LOW);
digitalWrite(horz_motor2, HIGH);
digitalWrite(horz_motor_led, HIGH);
speed_horz = map(joyposhorz, 470, 0, 0, 255);
}
else if (joyposhorz > 550)
{
digitalWrite(horz_motor1, HIGH);
digitalWrite(horz_motor2, LOW);
digitalWrite(horz_motor_led, HIGH);
speed_horz = map(joyposhorz, 550, 1023, 0, 255);
}
if (speed_vert < 8)speed_vert = 0;
if (speed_horz < 8)speed_horz = 0;
analogWrite(mvert, speed_vert);
analogWrite(mhorz, speed_horz);
}
}