IRLineSensor

#define IN1 A0 #define IN2 A1 #define IN3 A2 #define IN4 A3 #define INLINE 1; // Motor direction #define M_LEFT 12 #define M_RIGHT 13 void initSensor(); // Init the port for the IR, in default, it's from A0 to A3 void isInLine(); //Return true if the IR 1 and 3 are on the line, it means the device is running right way void getStatus(); //Return two value: M_LEFT if the car need turning left, M_RIGHT if the car need turning right void initSensor() { pinMode(IN1, INPUT); pinMode(IN2, INPUT); pinMode(IN3, INPUT); pinMode(IN4, INPUT); } boolean isInLine() { // If the value of ir > 300 it's inline, else it's outline // Bang has written the above comment, but only god knows is it true, check plz int ir1 = analogRead(IN1); int ir2 = analogRead(IN2); int ir3 = analogRead(IN3); int ir4 = analogRead(IN4); if ((ir1>300) && (ir3>300)) return true; return false; } int getStatus() { if (analogRead(IN2)>300) // check return M_RIGHT; // it if (analogRead(IN4)>300) // again return M_LEFT; // p if (isInLine()) // l return INLINE; // z return 0; } int getValue(int port) { return analogRead(port); }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.