Paso 7:
Código de control simple: Utilice el sensor de ultrasonidos para detectar prospectos y las cuatro barras de varillaje para iniciar un intercambio de movimiento para distribuir folletos.
<p>#include </p><p>#define PAPER_DIS 8</p><p>MeDCMotor pump(M1); MeDCMotor arm(M2); MeUltrasonicSensor dis(PORT_3); MeLimitSwitch limit(PORT_4, SLOT1);</p><p>unsigned long startTime = 0; unsigned long currentTime = 0;</p><p>void setup() { Serial.begin(9600); arm.run(180); startTime = millis(); do { currentTime = millis(); } while(!((limit.touched()) || (currentTime - startTime > 3000))); arm.stop(); }</p><p>void loop() { while (!paperDetected()) { arm.run(-250); while (!paperDetected()) { delay(100); } pump.run(255); delay(1200); arm.stop(); delay(500); // Raise arm.run(180); delay(1500); } startTime = millis(); do { currentTime = millis(); } while(!((limit.touched()) || (currentTime - startTime > 3000))); arm.stop(); pump.run(200); }</p><p>int paperDetected() { float distance = 0; do { distance = dis.distanceCm(); } while (distance < 2); if (distance < PAPER_DIS) { return 1; } else { return 0; } }</p>