-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
79 lines (67 loc) · 1.87 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <iostream>
#include <pico/stdlib.h>
#include "LCD.h"
#include "RgbLed.h"
#include "Sonar.h"
#include "RotaryEncoder.h"
static constexpr int lcdD4Pin = 21;
static constexpr int lcdD5Pin = 20;
static constexpr int lcdD6Pin = 19;
static constexpr int lcdD7Pin = 18;
static constexpr int lcdEnPin = 16;
static constexpr int lcdRsPin = 17;
static constexpr int lcdV0Pin = 22;
static constexpr int ledRedPin = 11;
static constexpr int ledGreenPin = 12;
static constexpr int ledBluePin = 13;
static constexpr int sonarTrigPin = 26;
static constexpr int sonarEchoPin = 27;
static constexpr int knobAPin = 14;
static constexpr int knobBPin = 15;
static constexpr int knobSwPin = 10;
using std::cout;
using std::endl;
int main(void)
{
stdio_init_all();
cout << "Starting" << endl;
LCD _lcd(lcdD4Pin,
lcdD5Pin,
lcdD6Pin,
lcdD7Pin,
lcdEnPin,
lcdRsPin,
lcdV0Pin);
_lcd.init();
_lcd.set_contrast(25);
RgbLed _rgbLed(ledRedPin,
ledGreenPin,
ledBluePin);
Sonar _sonar(sonarTrigPin,
sonarEchoPin);
RotaryEncoder _knob(knobAPin,
knobBPin,
knobSwPin);
for (int i = 0; true; i++)
{
sleep_ms(100);
cout << "Hej " << i << endl;
_sonar.startMeasurement();
_lcd.clear();
char str[32];
int distance = _sonar.getMeasurementMm();
int knobPos = _knob.position();
if (distance < 1000)
{
snprintf(str, 32, "%u cm %u", distance / 10, knobPos);
int level = distance * distance / 10000;
_rgbLed.set_color(level, level, level);
}
else
{
snprintf(str, 32, "-- cm %u", knobPos);
_rgbLed.set_color(0, 0, 0);
}
_lcd.print(str);
}
}