Blame | Last modification | View Log | RSS feed
/*433Mhz Reviever ConnectionsView from front__________________________| ||_A_G_G_V__________V_D_D_G_|| | | | | | | |^ ^ ^5V D2 GndMotorShield ConnectionsM1___G__M2_|o|o||o||o|o|^ ^ ^ ^| | | |+R -R -L +LR = Right motor, L = Left motor*/#include <VirtualWire.h>#include <AFMotor.h>AF_DCMotor motor1(1, MOTOR12_2KHZ); //RightAF_DCMotor motor2(2, MOTOR12_2KHZ); //Leftconst int rxPin = 2;const int rxBps = 2000;const int MRIGHT = 0;const int MLEFT = 1;const int MFORWARD = 1;const int MREVERSE = 0;void setup(){Serial.begin(9600); // Debugging onlySerial.println("setup");vw_set_rx_pin(rxPin);vw_setup(rxBps); // Bits per secvw_rx_start(); // Start the receiver PLL running// Start motors idlemotor1.setSpeed(0);motor2.setSpeed(0);motor1.run(RELEASE);motor2.run(RELEASE);}void loop(){uint8_t buf[VW_MAX_MESSAGE_LEN];uint8_t buflen = VW_MAX_MESSAGE_LEN;if (vw_get_message(buf, &buflen)) // Non-blocking{digitalWrite(13, true); // Flash a light to show received good messagedigitalWrite(13, false);/*int i;Serial.print("Got: ");for (i = 0; i < buflen; i++){Serial.print(buf[i], HEX);Serial.print(" ");}Serial.println("");*/int mspd[2] = {0, 0}; //Speed of right trackint options = 0; // Optionsif (buf[0]) // Read the optionsoptions = buf[0] - 1;if (buf[1]) // Right speedmspd[MRIGHT] = buf[1] -1;if (buf[2]) // Left speedmspd[MLEFT] = buf[2] -1;Serial.print("options "); Serial.print(options, BIN);Serial.print(" r_spd "); Serial.print(mspd[MRIGHT], DEC);Serial.print(" l_spd "); Serial.print(mspd[MLEFT], DEC);Serial.println("");// Start the tracks rollingif (mspd[MRIGHT] > 0) {motor1.setSpeed(mspd[MRIGHT]);if (bitRead(options, MRIGHT))motor1.run(FORWARD);elsemotor1.run(BACKWARD);} elsemotor1.run(RELEASE);if (mspd[MLEFT] > 0) {motor2.setSpeed(mspd[MLEFT]);if (bitRead(options, MLEFT))motor2.run(FORWARD);elsemotor2.run(BACKWARD);} elsemotor2.run(RELEASE);}}