lib Modulove
Library for building custom scripts for Modulove modules.
Loading...
Searching...
No Matches
analog_output.h
Go to the documentation of this file.
1
11#ifndef ANALOGL_OUTPUT_H
12#define ANALOG_OUTPUT_H
13
14#include <Arduino.h>
15
16namespace modulove {
17
18const int MAX_OUTPUT = (1 << 8) - 1; // Max 8 bit output resolution.
19const int MAX_OUTPUT_10BIT = (1 << 10) - 1; // Max 10 bit output resolution.
20
22 public:
28 void Init(uint8_t pin) {
29 pinMode(pin, OUTPUT); // Analog CV Output
30 cv_pin_ = pin;
31 }
32
39 void Init(uint8_t cv_pin, uint8_t led_pin) {
40 pinMode(led_pin, OUTPUT); // LED
41 led_pin_ = led_pin;
42 #define LED_PIN_DEFINED
43 Init(cv_pin);
44 }
45
51 inline void Update(int val) {
52 update((val <= MAX_OUTPUT) ? val : MAX_OUTPUT);
53 }
54
60 inline void Update10bit(int val) {
61 val = val <= MAX_OUTPUT_10BIT ? val : MAX_OUTPUT_10BIT;
62 val = map(val, 0, MAX_OUTPUT_10BIT, 0, MAX_OUTPUT);
63 update(val);
64 }
65
67 inline void High() { update(MAX_OUTPUT); }
68
70 inline void Low() { update(0); }
71
77 inline uint16_t GetValue() { return cv_; }
78
79 private:
80 uint8_t cv_pin_;
81 uint8_t led_pin_;
82 uint8_t cv_;
83
84 void update(uint16_t val) {
85 cv_ = val;
86 analogWrite(cv_pin_, cv_);
87 #ifdef LED_PIN_DEFINED
88 analogWrite(led_pin_, cv_);
89 #endif
90 }
91};
92
93} // namespace modulove
94
95#endif
Definition analog_output.h:21
void Init(uint8_t pin)
Initializes an Analog CV Output object.
Definition analog_output.h:28
void Update10bit(int val)
Set the output pin to the given 10 bit value.
Definition analog_output.h:60
void Init(uint8_t cv_pin, uint8_t led_pin)
Initializes an LED & CV Output paired object.
Definition analog_output.h:39
void Low()
Sets the cv output LOW to 0v.
Definition analog_output.h:70
void Update(int val)
Set the output pin to the given 8 bit value.
Definition analog_output.h:51
void High()
Sets the cv output HIGH to about 10v.
Definition analog_output.h:67
uint16_t GetValue()
Return an integer value between 0 and 1023 (0..10v) representing the current value of the output.
Definition analog_output.h:77