Skip to content

Commit 72e16dc

Browse files
ATATCHaydenHour
andauthored
Support Pedals as Built-in Devices (#481)
* Support Pedals as Built-in Devices (#480) * Added paddle support. * Initial Pedal Code (Need to adust numbers) * Adjusted values * #206 fixed variables to more percise values * Wrapped as a LEADS device. (#206) * Added the corresponding Python binding. (#206) --------- Co-authored-by: HaydenHour <154443692+HaydenHour@users.noreply.github.com>
1 parent 0750ce3 commit 72e16dc

5 files changed

Lines changed: 57 additions & 0 deletions

File tree

arduino/leads_vec_power/Pedal.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include "Pedal.h"
2+
3+
Pedal::Pedal(const ArrayList<int> &pins, float restValue, float maxValue) : Device<float>(pins), _restValue(restValue), _maxValue(maxValue) {}
4+
5+
Pedal::initialize(const ArrayList<String> &parentTags) {
6+
Device<float>::initialize(parentTags);
7+
pinMode(_pins[0], INPUT);
8+
}
9+
10+
float Pedal::read() { return ((float) analogRead(_pins[0]) / 1023 - _restValue) / _maxValue; }

arduino/leads_vec_power/Pedal.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#ifndef PEDAL_H
2+
#define PEDAL_H
3+
4+
5+
#include "Device.h"
6+
7+
class Pedal : public Device<float> {
8+
protected:
9+
float _restValue, _maxValue;
10+
11+
public:
12+
VoltageSensor(const ArrayList<int> &pins, float restValue, float maxValue);
13+
void initialize(const ArrayList<String> &parentTags) override;
14+
float read() override;
15+
};
16+
17+
18+
#endif // PEDAL_H

arduino/leads_vec_power/leads_vec_power.ino

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "LEADS.h"
2+
#include "Pedal.h"
23

34
const int PIN_VOT[] = {A0};
45

leads_arduino/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
from leads_arduino.arduino_proto import *
88
from leads_arduino.arduino_nano import *
99
from leads_arduino.arduino_micro import *
10+
from leads_arduino.pedal import *
1011
from leads_arduino.voltage_sensor import *
1112
from leads_arduino.wheel_speed_sensor import *

leads_arduino/pedal.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from typing import override as _override
2+
3+
from leads import Device as _Device
4+
5+
6+
class Pedal(_Device):
7+
"""
8+
See LEADS-Arduino.
9+
10+
Supports:
11+
- Any analog pedal
12+
"""
13+
14+
def __init__(self) -> None:
15+
super().__init__()
16+
self._position: float = 0
17+
18+
@_override
19+
def update(self, data: str) -> None:
20+
self._position = float(data)
21+
22+
@_override
23+
def read(self) -> float:
24+
"""
25+
:return: pedal position that ranges from 0 to 1
26+
"""
27+
return self._position

0 commit comments

Comments
 (0)