AccelStepperI2C  v 0.1
I2C wrapper (and a bit more) for the AccelStepper Arduino library
Servo_Sweep.ino
Go to the documentation of this file.
1 /*
2  ServoI2C Sweep demo
3  (c) juh 2022
4 
5  This is a 1:1 equivalent of the Servo library's Sweep example
6  https://docs.arduino.cc/learn/electronics/servo-motors
7 
8 */
9 
10 #include <Wire.h>
11 #include <ServoI2C.h>
12 
13 uint8_t i2cAddress = 0x08;
14 
15 I2Cwrapper wrapper(i2cAddress); // each slave device is represented by a wrapper...
16 ServoI2C myservo(&wrapper); // ...that the servo needs to communicate with the slave
17 
18 int pos = 0; // variable to store the servo position
19 
20 void setup()
21 {
22  Wire.begin();
23  // Serial.begin(115200); // uncomment for debugging output (needs DEBUG set in firmware/libraries)
24  // Wire.setClock(10000); // uncomment for ESP8266 slaves, to be on the safe side
25 
26  wrapper.reset(); // reset the slave device
27  delay(500); // and give it time to reboot
28 
29  myservo.attach(9); // attaches the servo on _the slave's_ pin 9 to the servo object
30 
31 }
32 
33 void loop()
34 {
35  for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
36  // in steps of 1 degree
37  myservo.write(pos); // tell servo to go to position in variable 'pos'
38  delay(15); // waits 15ms for the servo to reach the position
39  }
40  for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
41  myservo.write(pos); // tell servo to go to position in variable 'pos'
42  delay(15); // waits 15ms for the servo to reach the position
43  }
44 }
I2Cwrapper
A helper class for the AccelStepperI2C (and ServoI2C) library.
Definition: I2Cwrapper.h:79
i2cAddress
uint8_t i2cAddress
Definition: Servo_Sweep.ino:13
wrapper
I2Cwrapper wrapper(i2cAddress)
Definition: Servo_Sweep.ino:16
pos
int pos
Definition: Servo_Sweep.ino:18
ServoI2C
An I2C wrapper class for the Arduino Servo library.
Definition: ServoI2C.h:65
loop
void loop()
Definition: Servo_Sweep.ino:33
ServoI2C.h
Arduino library for I2C-control of servo motors connected to another Arduino which runs the associate...
I2Cwrapper::reset
void reset()
Tells the slave to reset to it's default state. It is recommended to reset the slave every time the m...
Definition: I2Cwrapper.cpp:108
setup
void setup()
Definition: Servo_Sweep.ino:20