Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
boebot-public
/
eriala-2024
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
11580d4d
authored
7 months ago
by
Risto Heinsar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added wk 4 starter code for the lab
parent
61d1d3fb
master
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
91 additions
and
0 deletions
lab4_starter/lab4_starter.ino
lab4_starter/lab4_starter.ino
0 → 100644
View file @
11580d4d
#include <Servo.h>
#define RIGHT_LED_PIN 7
#define LEFT_LED_PIN 8
#define LEFT_QTI_PIN A0
#define MIDDLE_QTI_PIN A1
#define RIGHT_QTI_PIN A2
#define RIGHT_SERVO_PIN 5
#define LEFT_SERVO_PIN 6
#define SERVO_MIN_PULSE 1300
#define SERVO_MAX_PULSE 1700
#define SERVO_STANDSTILL 1500
#define QTI_THRESHOLD 0 // Pane siia õige väärtus!
/* Servomootorite globaalmuutujate deklaratsioonid */
Servo
leftWheel
;
Servo
rightWheel
;
void
setup
()
{
/* Konfigureerime LEDid väljundiks */
pinMode
(
LEFT_LED_PIN
,
OUTPUT
);
pinMode
(
RIGHT_LED_PIN
,
OUTPUT
);
/* Konfigureerime servomootorid */
leftWheel
.
attach
(
LEFT_SERVO_PIN
,
SERVO_MIN_PULSE
,
SERVO_MAX_PULSE
);
rightWheel
.
attach
(
RIGHT_SERVO_PIN
,
SERVO_MIN_PULSE
,
SERVO_MAX_PULSE
);
/* Anname servodemootorite külge võtmiseks hetke aega */
delay
(
10
);
/* Seadistame servomootorid seisvale asendile */
SetWheels
(
SERVO_STANDSTILL
,
SERVO_STANDSTILL
);
}
void
loop
()
{
bool
leftQtiSeesBlack
=
IsQtiDetectingBlack
(
LEFT_QTI_PIN
);
bool
rightQtiSeesBlack
=
IsQtiDetectingBlack
(
RIGHT_QTI_PIN
);
/* Vastavalt sensori tulemustele otsustame käitumise */
if
(
leftQtiSeesBlack
&&
rightQtiSeesBlack
)
{
MoveForward
(
20
);
}
//else if (/* Jätka tingimuste kirjutamist */)
{
}
}
void
MoveForward
(
uint16_t
time
)
{
SetWheels
(
1700
,
1300
);
SetLed
(
HIGH
,
HIGH
);
delay
(
time
);
}
void
SetWheels
(
int
leftWheelImpulseLength
,
int
rightWheelImpulseLength
)
{
leftWheel
.
writeMicroseconds
(
leftWheelImpulseLength
);
rightWheel
.
writeMicroseconds
(
rightWheelImpulseLength
);
}
bool
IsQtiDetectingBlack
(
uint8_t
qtiPin
)
{
/* Lülitame infrapuna dioodi sisse 1 ms*/
digitalWrite
(
qtiPin
,
HIGH
);
delayMicroseconds
(
1000
);
digitalWrite
(
qtiPin
,
LOW
);
/* Loeme kondensaatori pinge */
uint16_t
qtiValue
=
analogRead
(
qtiPin
);
/* Tavastame kas oli üle nivoo (tõene / väär) ehk tuvastas musta värvi */
return
qtiValue
>
QTI_THRESHOLD
;
}
void
SetLed
(
uint8_t
leftLedState
,
uint8_t
rightLedState
)
{
digitalWrite
(
RIGHT_LED_PIN
,
leftLedState
);
digitalWrite
(
LEFT_LED_PIN
,
rightLedState
);
}
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment