starting some code
This commit is contained in:
25
.vscode/settings.json
vendored
25
.vscode/settings.json
vendored
@@ -1,17 +1,22 @@
|
||||
{
|
||||
"cmake.configureOnOpen": false,
|
||||
"cmake.statusbar.advanced": {
|
||||
"debug" : {
|
||||
"debug": {
|
||||
"visibility": "hidden"
|
||||
},
|
||||
"launch" : {
|
||||
},
|
||||
"launch": {
|
||||
"visibility": "hidden"
|
||||
},
|
||||
"build" : {
|
||||
},
|
||||
"build": {
|
||||
"visibility": "hidden"
|
||||
},
|
||||
"buildTarget" : {
|
||||
},
|
||||
"buildTarget": {
|
||||
"visibility": "hidden"
|
||||
},
|
||||
},
|
||||
}
|
||||
},
|
||||
},
|
||||
"clang-format.executable": "C:/qt/qt-creator-8_win_x64/bin/clang-format.exe",
|
||||
"editor.formatOnSave": true,
|
||||
"[cpp]": {
|
||||
"editor.defaultFormatter": "demiaochen.clang-format-indent-4",
|
||||
},
|
||||
}
|
||||
@@ -1,14 +1,50 @@
|
||||
#include <stdio.h>
|
||||
#include "pico/stdlib.h"
|
||||
|
||||
void gpio_init_out(uint gpio) {
|
||||
gpio_set_dir(gpio, GPIO_OUT);
|
||||
gpio_put(gpio, 0);
|
||||
gpio_set_function(gpio, GPIO_FUNC_SIO);
|
||||
}
|
||||
|
||||
void gpio_callback(uint gpio, uint32_t events) {}
|
||||
|
||||
int main()
|
||||
{
|
||||
stdio_init_all();
|
||||
class Valve {
|
||||
public:
|
||||
Valve(uint gpio_motor1, uint gpio_motor2, uint gpio_start, uint gpio_end)
|
||||
: motor1(gpio_motor1), motor2(gpio_motor2), start_pin(gpio_start),
|
||||
end_pin(gpio_end) {
|
||||
gpio_init_out(motor1);
|
||||
gpio_init_out(motor2);
|
||||
gpio_set_irq_enabled_with_callback(start_pin, GPIO_IRQ_EDGE_RISE, true,
|
||||
&gpio_callback);
|
||||
gpio_set_irq_enabled_with_callback(end_pin, GPIO_IRQ_EDGE_RISE, true,
|
||||
&gpio_callback);
|
||||
}
|
||||
|
||||
void open() {
|
||||
gpio_put(motor2, 0);
|
||||
gpio_put(motor1, 1);
|
||||
}
|
||||
|
||||
puts("Hello, world!");
|
||||
void close() {
|
||||
gpio_put(motor1, 0);
|
||||
gpio_put(motor2, 1);
|
||||
}
|
||||
|
||||
private:
|
||||
uint motor1, motor2;
|
||||
uint start_pin, end_pin;
|
||||
};
|
||||
|
||||
int main() {
|
||||
Valve *v = new Valve(0, 1, 4, 5);
|
||||
|
||||
gpio_init_out(PICO_DEFAULT_LED_PIN);
|
||||
while (true) {
|
||||
gpio_put(PICO_DEFAULT_LED_PIN, 1);
|
||||
sleep_ms(200);
|
||||
gpio_put(PICO_DEFAULT_LED_PIN, 0);
|
||||
sleep_ms(200);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user