/*############################################################################## Author: * Mirko Prosseda (05-2017) * email: mirko.prosseda@gmail.com Description: * Easy Motor Controller V2 test sketch v1.0 * Read potentiometer analog value and send its value on I2C bus to the Easy Motor Controller. * Limit switches status are printed on Serial Monitor every second * A blinking led indicates running communication Connections: * BOARD -> ARDUINO * GND -> GND * SCL -> A5 * SDA -> A4 * Potentiometer must be connected to the A0 analog input ##############################################################################*/ #include // library used with I2C protocol // Define constants and variables #define I2C_address 0x0C // used without jumper on ADR connector //#define I2C_address 0x0D // used with jumper on ADR connector const int analogInPin = A0; int led = 13; int potValue; unsigned long ms; // Initialization void setup() { Wire.begin(); Serial.begin(9600); pinMode(led, OUTPUT); ms = millis(); } void blink_led() { digitalWrite(led, HIGH); delay(25); digitalWrite(led, LOW); delay(25); } void loop() { potValue = analogRead(analogInPin) / 4; Wire.beginTransmission(I2C_address); Wire.write(potValue); Wire.endTransmission(); blink_led(); if((millis() - ms) > 1000) { ms = millis(); Wire.requestFrom(I2C_address, 1); while(Wire.available()) { char c = Wire.read(); if(c & 0x01) Serial.print("S1 = OFF"); else Serial.print("S1 = ON "); if((c >> 1) & 0x01) Serial.println(" - S2 = OFF"); else Serial.println(" - S2 = ON"); } } }