Last active
October 10, 2015 22:18
-
-
Save pingswept/3759443 to your computer and use it in GitHub Desktop.
I2C motor control code for Rascal/Arduino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Motor number 1 (Front) is 29 hex or 41 decimal | |
#include <Wire.h> | |
#include <AFMotor.h> | |
AF_DCMotor motor(4); | |
int x=0; | |
void setup() | |
{ | |
Wire.begin(41); // Set I2C address | |
Wire.onReceive(receiveEvent); // Set up interrupt handler | |
motor.setSpeed(200); | |
motor.run(RELEASE); | |
} | |
void loop() | |
{ | |
motor.run(FORWARD); | |
motor.setSpeed(x); | |
} | |
void receiveEvent(int nothing) | |
{ | |
x = Wire.read(); // receive byte as an integer | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment