This is my first post here so there might be some mistakes, sorry!
I'm trying to connect Google Teachable Machine(https://teachablemachine.withgoogle.com/) and arduino Leonardo to make a device which automatically sorts grabage to two separate bins.
Need to control 1 servo motor, and though the code was fine when I uploaded it, the motor doesn't move
Partially used the code provided by Teachable Machine's own project, Tiny Sorter.
#include <WebUSB.h>
#include <Servo.h>
WebUSB WebUSBSerial(1 /* https:// */, "editor.p5js.org/gbose/full/2BN5HQYNK");
#define Serial WebUSBSerial
int servoPin=9;
int TM_value[3]; //color
int Index; // colorindex
int angle=0;
void setup() {
Servo myServo;
Serial.begin(9600);
myServo.attach(servoPin);
myServo.write(30);
}
void loop() {
Servo myServo;
if (Serial&&Serial.available()>0) {
Serial.read();
TM_value[Index++]=Serial.read();
Serial.println(TM_value[Index]);
if (Index==1){
if(TM_value[0]==1){
while(angle>30){
angle--;
myServo.write(angle);
delay(10);
}
}
else if(TM_value[0]==2){
while(angle<85){
angle++;
myServo.write(angle);
delay(10);
}
}
Index=0;
}
}
}