summaryrefslogtreecommitdiff
path: root/robot
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2022-05-26 17:41:26 +0200
committerlonkaars <loek@pipeframe.xyz>2022-05-26 17:41:26 +0200
commit6a1c9853402f623ef9eba76556a9a0213f04d3c8 (patch)
tree1aa57562958f0d87bafc7bf4ae1dcfc595f0306b /robot
parent8995e8b1f29f9c5da4d8c08fafcba53c58ee7947 (diff)
parent0b314c2ea19f0ae33a1b6c47f8b1140f22e78d2a (diff)
Merge branch 'HoodieJeansJordans-master'
Diffstat (limited to 'robot')
-rw-r--r--robot/io.c51
-rw-r--r--robot/io.h56
2 files changed, 104 insertions, 3 deletions
diff --git a/robot/io.c b/robot/io.c
index 4a85458..5757ffd 100644
--- a/robot/io.c
+++ b/robot/io.c
@@ -1,3 +1,52 @@
#include "io.h"
+#include <pololu/orangutan.h>
-void w2_io_main() {}
+
+w2_io_all global;
+
+void w2_io_main() {
+ global.button[0] = get_single_debounced_button_press(BUTTON_A);
+ global.button[1] = get_single_debounced_button_press(BUTTON_B);
+ global.button[2] = get_single_debounced_button_press(BUTTON_C);
+ global.button[3] = get_single_debounced_button_press(TOP_BUTTON);
+ global.button[4] = get_single_debounced_button_press(BOTTOM_BUTTON);
+ unsigned int sensor_values[5];
+ qtr_read(sensor_values, QTR_EMITTERS_ON);
+ for(int i = 0; i <5; i++){
+ global.qtrSensor[i] = sensor_values[i];
+ }
+ // TODO average voltage over mutiple samples sensor
+ global.batteryLevel = analog_read(BATTERY_PIN);
+ global.frontDetection = analog_read(FRONT_SENSOR_PIN);
+ global.sideDetection = analog_read(SIDE_SENSOR_PIN);
+
+ set_motors(global.motor_left, global.motor_right);
+ red_led(global.led_red);
+ green_led(global.led_green);
+ print_character(global.lcd);
+};
+
+void w2_io_init(){
+ pololu_3pi_init(2000):
+
+ for(counter=0;counter<80;counter++)
+ {
+ if(counter < 20 || counter >= 60)
+ {
+ global.motor_left=40;
+ global.motor_right=-40;
+ }
+ else
+ {
+ global.motor_left=-40;
+ global.motor_right=40;
+ }
+
+ calibrate_
+ line_sensors(IR_EMITTERS_ON);
+
+ delay_ms(20);
+ }
+ global.motor_left=0;
+ global.motor_right=0;
+} \ No newline at end of file
diff --git a/robot/io.h b/robot/io.h
index 14fe0af..e262fa1 100644
--- a/robot/io.h
+++ b/robot/io.h
@@ -1,4 +1,56 @@
#pragma once
+#include <stdlib.h>
+#include <stdint.h>
+#include <stdbool.h>
+#define FRONT_SENSOR_PIN 5
+#define SIDE_SENSOR_PIN 7
+#define BATTERY_PIN 6
-/** i/o module main */
-void w2_io_main();
+//inputs
+
+typedef struct {
+ bool pressed;
+} w2_s_io_push;
+
+typedef struct {
+ uint16_t range;
+
+} w2_s_io_contrast;
+
+typedef struct {
+ uint16_t detection;
+} w2_s_io_distance;
+
+//outputs
+
+typedef struct {
+ int speed;
+} w2_s_io_motor;
+
+typedef struct {
+ bool toggle;
+} w2_s_io_led;
+
+typedef struct {
+ char text[16];
+} w2_s_io_display;
+typedef struct {
+ uint8_t charged;
+} w2_s_io_battery;
+
+//all i/o
+
+typedef struct {
+ w2_s_i_push button[5];
+ w2_s_i_contrast qtrSensor[5];
+ w2_s_i_distance frontDetection;
+ w2_s_i_distance sideDetection;
+ w2_s_i_battery batteryLevel;
+
+
+ w2_s_o_motor motor_left;
+ w2_s_o_motor motor_right;
+ w2_s_o_led led_red;
+ w2_s_o_led led_green;
+ w2_s_o_display lcd;
+} w2_io_all;