passer au contenu principal
paste
bin
.ca
type · paste · share
⌘
K
Famille
La famille bin
pastebin.ca
pôle
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
Se connecter
?
← retour au collage
›
Modifier / dupliquer
Collage sans titre
#8k9dpaHY5Q
public / public
nouvelle version
anonyme
créé 3 days ago
Expire dans 4 days
3.3 KB
syntaxe:
text
Vos changements créent un nouveau collage lié à celui-ci — l’original reste intact.
nouvelle version
Vos changements créent un nouveau collage lié à celui-ci — l’original reste intact.
Titre (facultatif)
Nom de fichier
Syntaxe
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
Visibilité
Fil public
Accès
public
Expire
7 jours
10 min
1 heure
1 jour
7 jours
30 jours
90 jours
personnalisé…
Expiration personnalisée
Note de changement
(facultatif)
Ce collage sera affiché dans le fil public. Changez la visibilité si vous voulez seulement le partager par lien.
Créer une nouvelle version
Annuler
Collez ou tapez…
/* 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); } } }