I don’t intend to use MakeBlock software, just looking at the comments inside it make me feel uneasy, I’ll write all my own code. But since MakeBlock’s documentation is awful, and since people here have helped me, I thought I’d post some info that others in my situation would find useful.
This photo shows pins to use in your sketch with limit switches, cables and servos,
Here’s a sketch to test the pen servo movement. Iy’ll move it a little biut every half a second:
#include <Servo.h>
Servo myservo; // Create the servo object
void setup() {
myservo.attach(A1); // Make the servo use pin A1 on Port 7 of the Orion
}
void loop() {
int degs = random (70,110) ; // Servo "default" is at 90. Make a random number around 90°
myservo.write(degs); // Sets the servo position in degrees
delay(500); // Pause so you can see where it has moved
}
And here’s a sketch to test one pair of limit switches. Once uploaded onto the Orion you’ll need to get the serial monitor screen going (icon at extreme right of the toolba). Then every time you push one of the microswitches the sketch will print out the change.
void setup()
{
Serial.begin(9600);
pinMode (A3,INPUT_PULLUP);
pinMode (A2,INPUT_PULLUP);
Serial.println("start");
}
int iOldY1 = 0 ;
int iOldY2 = 0 ;
void loop()
{
int iNewY1 = digitalRead (A3) ;
int iNewY2 = digitalRead (A2) ;
if ((iNewY1 != iOldY1) || (iNewY2 != iOldY2)) {
Serial.print ("A3=") ;
Serial.print (iNewY1) ;
Serial.print (" A2=") ;
Serial.print (iNewY2) ;
Serial.println("") ;
}
iOldY1 = iNewY1 ;
iOldY2 = iNewY2 ;
}
To test the other pair of limit switches just change A3 and A2 everywhere in the sketch above to 12 and 13.
Hope this helps someone!