Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions arduino/leads_vec_power/Pedal.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include "Pedal.h"

Pedal::Pedal(const ArrayList<int> &pins, float restValue, float maxValue) : Device<float>(pins), _restValue(restValue), _maxValue(maxValue) {}

Pedal::initialize(const ArrayList<String> &parentTags) {
Device<float>::initialize(parentTags);
pinMode(_pins[0], INPUT);
}

float Pedal::read() { return ((float) analogRead(_pins[0]) / 1023 - _restValue) / _maxValue; }
18 changes: 18 additions & 0 deletions arduino/leads_vec_power/Pedal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef PEDAL_H
#define PEDAL_H


#include "Device.h"

class Pedal : public Device<float> {
protected:
float _restValue, _maxValue;

public:
VoltageSensor(const ArrayList<int> &pins, float restValue, float maxValue);
void initialize(const ArrayList<String> &parentTags) override;
float read() override;
};


#endif // PEDAL_H
1 change: 1 addition & 0 deletions arduino/leads_vec_power/leads_vec_power.ino
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "LEADS.h"
#include "Pedal.h"

const int PIN_VOT[] = {A0};

Expand Down
1 change: 1 addition & 0 deletions leads_arduino/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
from leads_arduino.arduino_proto import *
from leads_arduino.arduino_nano import *
from leads_arduino.arduino_micro import *
from leads_arduino.pedal import *
from leads_arduino.voltage_sensor import *
from leads_arduino.wheel_speed_sensor import *
27 changes: 27 additions & 0 deletions leads_arduino/pedal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from typing import override as _override

from leads import Device as _Device


class Pedal(_Device):
"""
See LEADS-Arduino.

Supports:
- Any analog pedal
"""

def __init__(self) -> None:
super().__init__()
self._position: float = 0

@_override
def update(self, data: str) -> None:
self._position = float(data)

@_override
def read(self) -> float:
"""
:return: pedal position that ranges from 0 to 1
"""
return self._position