pular para o conteúdo principal
paste
bin
.ca
type · paste · share
⌘
K
Família
A família bin
pastebin.ca
central
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
Entrar
?
← voltar para a publicação
›
Editar / bifurcar
Publicação sem título
#8k9dpaHY5Q
public / public
nova versão
anônimo
criado 3 days ago
Expira em 4 days
3.3 KB
sintaxe:
text
Suas alterações criam uma nova publicação vinculada a esta — a original não é alterada.
nova versão
Suas alterações criam uma nova publicação vinculada a esta — a original não é alterada.
Título (opcional)
Nome do arquivo
Sintaxe
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
Visibilidade
Feed público
Acesso
public
Expira
7 dias
10 min
1 hora
1 dia
7 dias
30 dias
90 dias
personalizada…
Expiração personalizada
Nota da alteração
(opcional)
Esta publicação aparecerá no feed público. Altere Visibilidade se quiser compartilhar apenas por link.
Criar nova versão
Cancelar
Cole ou digite…
/* 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); } } }