Go Down

Topic: serial driven robot (Read 1 time) previous topic - next topic

legoaceking

when i try to upload the code i get this


sketch_dec26a.cpp: In function 'void loop()':
sketch_dec26a:11: error: invalid conversion from 'const char*' to 'const uint8_t*'
sketch_dec26a:11: error: initializing argument 1 of 'virtual size_t Print::write(const uint8_t*, size_t)'
Loading...

el_supremo

yup, sorry. I'm still not up to speed with V1.0 !
Code: [Select]

#define MOTOR_PIN 10

void setup() {
    pinMode(MOTOR_PIN,INPUT);
    Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
}

void loop() {
    if (digitalRead(MOTOR_PIN)) {
        Serial.write((const uint8_t *)"a",1);
    } else {
        Serial.write((const uint8_t *)"b",1);
    }
}


Pete

legoaceking

it works sorta.
it keeps sending the signal for like 1 sec and then a blank signal.
Loading...

Mac Stevens


i can now control the robot using the computer but i still cant get the controler to control the robot.
i looked in the serial viewer and the controler seems to be sending sorta blank signals.


I don't have a button connected to pin 10, so I modified your code a little and fed this to my Arduino Uno:
Code: [Select]
void setup() {                
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps  // Pin 13 has an LED connected on most Arduino boards:

}

void loop() {
 
   Serial.write('a');
   delay(1000);
 
   Serial.write('b');
   delay(1000);
}


The serial monitor displayed this, just as expected:
Quote
ababababa


legoaceking

i added a delay to your code and it fixed the reseting.
the reason i cant get a 'a' signal is that the arduino mini keeps reseting when i press the trigger button.
i dont know how to fix that.

heres the moded code.

Code: [Select]
const int button1 = 10;

void setup() {
    pinMode(button1,INPUT);
    Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
}

void loop() {
    if (digitalRead(button1) == HIGH ) {
        Serial.write((const uint8_t *)"a",1);
    } else {
        Serial.write((const uint8_t *)"b",1);
    }
    delay(100);
}
Loading...

Go Up