saltar al contenido principal
paste
bin
.ca
type · paste · share
⌘
K
Familia
La familia bin
pastebin.ca
centro
Share text and code with expiry and privacy controls.
imagebin.ca
Upload and share images with direct links.
filebin.ca
Drop a file and get a shareable link.
notebin.ca
Write Markdown notes with durable links.
turl.ca
Short, reputation-checked links.
attn.ca
Notifications and alerts for your services.
voicebin.ca
Record and share short voice clips.
dnsbin.ca
Inspect DNS and debug records.
Docs
Iniciar sesión
?
← volver a la publicación
›
Editar / bifurcar
Publicación sin título
#8k9dpaHY5Q
public / public
nueva versión
anónimo
creado 3 days ago
Caduca en 4 days
3.3 KB
sintaxis:
text
Tus cambios crean una nueva publicación enlazada a esta — la original no se toca.
nueva versión
Tus cambios crean una nueva publicación enlazada a esta — la original no se toca.
Título (opcional)
Nombre de archivo
Sintaxis
text
text
bash
c
cpp
css
diff
dockerfile
go
html
ini
java
javascript
json
kotlin
lua
makefile
markdown
nginx
php
python
ruby
rust
shellscript
sql
swift
toml
typescript
xml
yaml
Visibilidad
Feed público
Acceso
public
Caduca
7 días
10 min
1 hora
1 día
7 días
30 días
90 días
personalizada…
Caducidad personalizada
Nota de cambio
(opcional)
Esta publicación aparecerá en el feed público. Cambia Visibilidad si solo quieres compartirla por enlace.
Crear nueva versión
Cancelar
Pegar o escribir…
/* ELEC1100 Your Lab#06 & Project Template To program the car tracking the white line on a dark mat Group No. (number of your project box): Group Member 1 (name & SID): Group Member 2 (name & SID): */ // assign meaningful names to those pins that will be used const int pinL_Sensor = A5; //pin A5: left sensor const int pinB_Sensor = A4; //pin A4: bumper sensor const int pinR_Sensor = A3; //pin A3: right sensor const int pinL_PWM = 9; //pin D9: left motor speed const int pinL_DIR = 10; //pin D10: left motor direction const int pinR_PWM = 11; //pin D11: right motor speed const int pinR_DIR = 12; //pin D12: right motor direction //define variables to be used in script int bumperSensor = 1; // not sensing white int leftSensor = 1; // not sensing white int rightSensor = 1; // not sensing white int countBumper = 0; // bumper sensor not triggered yet // the setup function runs once when you press reset or power the board void setup () { // define pins as input and output pinMode(pinB_Sensor, INPUT); pinMode(pinL_Sensor, INPUT); pinMode(pinR_Sensor, INPUT); pinMode(pinL_DIR, OUTPUT); pinMode(pinR_DIR, OUTPUT); pinMode(pinL_PWM, OUTPUT); pinMode(pinR_PWM, OUTPUT); // initialize output pins digitalWrite(pinL_DIR, HIGH); //forward direction digitalWrite(pinR_DIR, HIGH); //forward direction analogWrite(pinL_PWM, 0); //stop at the start position analogWrite(pinR_PWM, 0); //stop at the start position } // the loop function runs over and over again forever void loop() { // Arduino is reading the sensor measurements bumperSensor = digitalRead(pinB_Sensor); leftSensor = digitalRead(pinL_Sensor); rightSensor = digitalRead(pinR_Sensor); // car stops at the start position when bumper sensor no trigger if ( bumperSensor && countBumper == 0 ) { analogWrite(pinL_PWM, 0); analogWrite(pinR_PWM, 0); } // bumper sensor is triggered at the start position for the 1st time else if ( !bumperSensor && countBumper == 0) { analogWrite(pinL_PWM, 150); analogWrite(pinR_PWM, 150); countBumper = countBumper + 1; delay(350); //to let the car leave the start position with no miscount } // car is tracking on the white line else if ( bumperSensor && countBumper == 1) { if ( !leftSensor && !rightSensor ) { analogWrite(pinL_PWM, 180); analogWrite(pinR_PWM, 180); digitalWrite(pinL_DIR, HIGH); digitalWrite(pinR_DIR, HIGH); } // Case 2: Left sensor sees white, right sees dark -> Drifted right, steer left if ( !leftSensor && rightSensor ) { analogWrite(pinL_PWM, 50); analogWrite(pinR_PWM, 180); digitalWrite(pinL_DIR, HIGH); digitalWrite(pinR_DIR, HIGH); } // Case 3: Left sensor sees dark, right sees white -> Drifted left, steer right if ( leftSensor && !rightSensor ) { analogWrite(pinL_PWM, 180); analogWrite(pinR_PWM, 50); digitalWrite(pinL_DIR, HIGH); digitalWrite(pinR_DIR, HIGH); } // Case 4: Both sensors see dark -> Lost line, move forward to search if ( leftSensor && rightSensor ) { analogWrite(pinL_PWM, 150); analogWrite(pinR_PWM, 150); digitalWrite(pinL_DIR, HIGH); digitalWrite(pinR_DIR, HIGH); } } }