What this code does is
->Get data from EV3 ultrasound as either 1 or nothing
->Then it gets the data and if the data is 1, the servo motor turns.
#include "DualMC33926MotorShield.h" //library
#include <Wire.h> //library
#define SLAVE_ADDRESS 0x04
#include <Servo.h> //library
Servo myservo;
void stopIfFault()
{
if (md.getFault())
{
Serial.println("fault");
while(1);
}
}
int state;
int pos = 0; //position
void setup()
{
myservo.attach(9); //pin for the servo
Serial.begin(9600);
pinMode(pos, OUTPUT);
Serial.println("Dual MC33926 Motor Shield");
md.init();
Wire.begin(SLAVE_ADDRESS);
Wire.onReceive(receiveData);
Wire.onRequest(sendData);
Serial.begin(9600);
Serial.println("Ready!");
}
int val,flag = 0;
void loop()
{
if(flag==1)
{
Serial.print("active");
flag=0;
}
}
void receiveData(int byteCount)
{
while(Wire.available()>0)
{
val=Wire.read();
flag=1;
}
}
// callback for sending data
void sendData()
{
Wire.write(0x45);
}
// Serial.flush();
if (Serial.available() > 0) {
if (Serial.peek() == '1') {
Serial.read();
state = Serial.parseInt();
for(pos = 0; pos <= 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=0; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
while (Serial.available() > 0) {
Serial.read();
}
Currently I'm getting the message 'recieveData' was not declared in this scope.
I am using the dexter industries EV3 to Arduino connector.
Help.