Skip to content

Instantly share code, notes, and snippets.

@pingswept
Last active October 10, 2015 22:18
Show Gist options
  • Save pingswept/3759443 to your computer and use it in GitHub Desktop.
Save pingswept/3759443 to your computer and use it in GitHub Desktop.
I2C motor control code for Rascal/Arduino
// 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