Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Ultrasonic.h>
- Ultrasonic ultrasonic(7);
- #include <SparkFunMiniMoto.h>
- MiniMoto motor0(0xC4);
- MiniMoto motor1(0xC0);
- #define FAULTn 16
- #define startKnop 2
- #define anglePin A2
- #define ledPin 13
- #define afstandsmeter 7
- int snelheid = 20;
- int bocht = 0;
- int snelheidMotor1 = 0;
- int snelheidMotor2 = 0;
- int RangeInCentimeters = 0;
- boolean aan = false;
- void setup()
- {
- pinMode(FAULTn, INPUT);
- pinMode(startKnop, INPUT);
- pinMode(anglePin, INPUT);
- pinMode(ledPin, OUTPUT);
- pinMode(afstandsmeter, INPUT);
- Serial.begin(9600);
- }
- void loop() {
- if (digitalRead(startKnop) == HIGH) {
- if (aan == false) {
- aan = true;
- } else {
- aan = false;
- }
- delay(250);
- }
- }
- bocht = analogRead(anglePin);
- if (bocht > 823) {
- snelheidMotor1 = 0;
- }
- if (bocht < 200) {
- snelheidMotor2 = 0;
- }
- motor0.drive(snelheidMotor1);
- motor1.drive(snelheidMotor2);
- if (aan == true) {
- digitalWrite(ledPin, HIGH);
- motor0.drive(20);
- motor1.drive(20);}
- else {
- digitalWrite(ledPin, LOW);
- motor0.stop();
- motor1.stop(); }
- if (RangeInCentimeters < 10) {
- if (random(0, 2) == 0) {
- snelheidMotor1 = 0;
- snelheidMotor2 = 40;
- delay(500);
- }
- }
- else {
- snelheidMotor1 = 40;
- snelheidMotor2 = 0;
- delay(500);
- }
- {
- snelheidMotor1 = 40;
- snelheidMotor2 = 40;
- }
- {
- motor0.drive(snelheidMotor1);
- motor1.drive(snelheidMotor2);
- }
- {
- digitalWrite(ledPin, LOW);
- motor0.stop();
- motor1.stop();
- }
- {
- RangeInCentimeters = ultrasonic.MeasureInCentimeters ();
- Serial.print(RangeInCentimeters);
- Serial.println(" cm");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement