งานที่ 18 หุ่นยนต์หลบสิ่งกีดขวาง Arduino 2WD
HARDWARE SOFTWARE #include <NewPing.h> //Tell the Arduino where the sensor is hooked up NewPing sonar(10, 11); int enableA = 3; int pinA1 = 6; int pinA2 = 7; int enableB = 5; int pinB1 = 8; int pinB2 = 9; long inches; void setup() { pinMode(enableA, OUTPUT); pinMode(pinA1, OUTPUT); pinMode(pinA2, OUTPUT); pinMode(enableB, OUTPUT); pinMode(pinB1, OUTPUT); pinMode(pinB2, OUTPUT); pinMode(2, OUTPUT); pinMode(12, OUTPUT); pinMode(13, OUTPUT); } void loop() { //Run the motors at slightly less than full power analogWrite(enableA, 200); analogWrite(enableB, 200); //Ping the sensor and determine the distance in inches inches = sonar.ping_in(); //If the robot detects an obstacle less than four inches away, it will back up, then turn left; if no obstacle is detected, it will go forward if (inches < 5) { analogWrite(enableA, 255); analogWrite(e...