Squirrels have fuzzy tails.
0 Members and 1 Guest are viewing this topic.
#include <SoftwareServo.h>SoftwareServo s1, s2, s3, s4, sa, sb;int pin_s1, pin_s2, pin_s3, pin_s4, pin_sa, pin_sb;int pin_ir1, pin_ir2, pin_ir3;float read_cm(byte pin) { int tmp; tmp = analogRead(pin); if (tmp < 3) return -1; // invalid value return (6787.0 /((float)tmp - 3.0)) - 4.0;}void drive_forward(void) { for(int i = 0; i < 5000; i++) { s1.write(180); s2.write(180); s3.write(0); s4.write(0); SoftwareServo::refresh(); }}void drive_backwards(void) { for(int i = 0; i < 5000; i++) { s1.write(0); s2.write(0); s3.write(180); s4.write(180); SoftwareServo::refresh(); }}void drive_left(void) { for(int i = 0; i < 5000; i++) { s1.write(180); s2.write(180); s3.write(180); s4.write(180); SoftwareServo::refresh(); } }void drive_right(void) { for(int i = 0; i < 5000; i++) { s1.write(0); s2.write(0); s3.write(0); s4.write(0); SoftwareServo::refresh(); }}void setup() { pin_s1 = 2; pin_s2 = 4; pin_s3 = 6; pin_s4 = 8; pin_sa = 10; pin_sb = 12; pin_ir1 = 0; pin_ir2 = 2; pin_ir3 = 4; s1.attach(pin_s1); s2.attach(pin_s2); s3.attach(pin_s3); s4.attach(pin_s4); sa.attach(pin_sa); sb.attach(pin_sb); digitalWrite(13, HIGH);}void loop() { drive_forward(); drive_backwards(); drive_left(); drive_right();}
void drive_forward(void) { for(int i = 0; i < 5000; i++) { s1.write(180); s2.write(180); s3.write(0); s4.write(0); SoftwareServo::refresh(); }}
void drive_backwards(void) { for(int i = 0; i < 5000; i++) { s1.write(0); s2.write(0); s3.write(180); s4.write(180); SoftwareServo::refresh(); }}
void step(void) { for(int i = 0; i <= 180; i++) { s1.write(i); s2.write(i); s3.write(i); s4.write(i); delay(20); SoftwareServo::refresh(); }}
void drive_left(void) { s1.write(180); s2.write(180); s3.write(180); s4.write(180); for(int i = 0; i < 100; i++) { delay(10); //Delay 10ms SoftwareServo::refresh(); } }
#include <SoftwareServo.h>SoftwareServo sp1, sp2, sa, sb;int pin_sp1, pin_sp2, pin_sa, pin_sb;int pin_ir1, pin_ir2, pin_ir3;float read_cm(byte pin) { int tmp; tmp = analogRead(pin); if (tmp < 3) return -1; // invalid value return (6787.0 /((float)tmp - 3.0)) - 4.0;}void fwd(void) { sp1.write(180); sp2.write(0); for(int i = 0; i < 100; i++) { SoftwareServo::refresh(); delay(15); }}void back(void) { sp1.write(0); sp2.write(180); for(int i = 0; i < 100; i++) { SoftwareServo::refresh(); delay(15); }} void left(void) { sp1.write(180); sp2.write(180); for(int i = 0; i < 100; i++) { SoftwareServo::refresh(); delay(15); }}void right(void) { sp1.write(0); sp2.write(0); for(int i = 0; i < 100; i++) { SoftwareServo::refresh(); delay(15); }}void setup() { pin_sp1 = 3; pin_sp2 = 6; pin_sa = 10; pin_sb = 4; pin_ir1 = 0; pin_ir2 = 2; pin_ir3 = 4; sp1.attach(pin_sp1); sp2.attach(pin_sp2); digitalWrite(13, HIGH);}void loop() { fwd(); back(); left(); right();}
#include <ServoTimeTimer1.h>#define RmotorPin 9 // digital pin 9, PWM pin#define LmotorPin 10 // digital pin 10, PWM pinServoTimeTimer1 Lmotor;ServoTimeTimer1 Rmotor;byte Speed = 200;byte TurnSpeed = 50;byte Acc = 10;byte direction = 1;void setup() { Lmotor.attach(LmotorPin); Rmotor.attach(RmotorPin); Lmotor.write(1315); // rev 1015 - 1315 - 1615 fwd Rmotor.write(1330); // rev 1030 - 1330 - 1630 fwd}void loop(){ //get the commands here...}void Stop(){ switch (direction) { case 0: // direction = reverse for (int s=0; s <= Speed; s=s+Acc) { Lmotor.write(1315-Speed+s); // rev 1015 - 1315 - 1615 fwd Rmotor.write(1330-Speed+s); // rev 1030 - 1330 - 1630 fwd delay(20); } break; case 1: // direction = forward for (int s=0; s<=Speed; s=s+Acc) { Lmotor.write(1315+Speed-s); // rev 1015 - 1315 - 1615 fwd Rmotor.write(1330+Speed-s); // rev 1030 - 1330 - 1630 fwd delay(20); } break; case 2: // direction = left for (int s=0; s<=TurnSpeed; s=s+Acc) { Lmotor.write(1315+TurnSpeed-s); // rev 1015 - 1315 - 1615 fwd Rmotor.write(1330-TurnSpeed+s); // rev 1030 - 1330 - 1630 fwd delay(20); } break; case 3: // direction = right for (int s=0; s<=TurnSpeed; s=s+Acc) { Lmotor.write(1315-TurnSpeed+s); // rev 1015 - 1315 - 1615 fwd Rmotor.write(1330+TurnSpeed-s); // rev 1030 - 1330 - 1630 fwd delay(20); } break; }}void Forward(){ direction = 1; for (int f=0; f<=Speed; f=f+Acc) { Lmotor.write(1315+f); // rev 1015 - 1315 - 1615 fwd Rmotor.write(1330+f); // rev 1030 - 1330 - 1630 fwd delay(20); }}void Reverse(){ direction = 0; for (int r=0; r<=Speed; r=r+Acc) { Lmotor.write(1315-r); // rev 1015 - 1315 - 1615 fwd Rmotor.write(1330-r); // rev 1030 - 1330 - 1630 fwd delay(20); }}void TurnLeft(){ direction = 2; for (int L=0; L<=Speed; L=L+Acc) { Lmotor.write(1315+L); // rev 1015 - 1315 - 1615 fwd Rmotor.write(1330-L); // rev 1030 - 1330 - 1630 fwd delay(20); }}void TurnRight(){ direction = 3; for (int R=0; R<=Speed; R=R+Acc) { Lmotor.write(1315-R); // rev 1015 - 1315 - 1615 fwd Rmotor.write(1330+R); // rev 1030 - 1330 - 1630 fwd delay(20); }}