carb-sync/twinmax/twinmax.ino

58 lines
948 B
Arduino
Raw Normal View History

#include "twinmax.h"
2020-06-01 15:11:26 +00:00
#include <Arduino.h>
#include <SoftwareSerial.h>
#include <Wire.h>
Display oled(4);
Pressure pleft;
Pressure pright;
PushButton btn;
Potentiometer slider;
void setup()
{
Wire.begin();
Wire.setClock(400000L);
pleft.setup(PRESSURE_LEFT);
pright.setup(PRESSURE_RIGHT);
btn.setup(PUSH_BTN_PIN);
slider.setup(POTENTIOMETER_PIN);
Serial.begin(9600);
2020-06-01 15:11:26 +00:00
oled.begin();
oled.clear();
2020-06-01 15:11:26 +00:00
oled.apply();
}
void loop()
{
if( btn.tap() ){
mode = (mode == RELATIVE) ? ABSOLUTE : RELATIVE;
}
oled.clear();
2020-06-01 15:11:26 +00:00
if( mode == RELATIVE ){
const int16_t left = pleft.value();
const int16_t right = pright.value();
// print absolute
oled.progress(left, 10, 15);
oled.progress(right, 20, 25);
// relative
double diff = (right - left);
diff = diff * slider.range() / 128.0;
oled.progress(512 + diff, 0, 5, false);
oled.apply();
}
2020-06-01 15:11:26 +00:00
if( mode == ABSOLUTE ){
oled.apply();
}
2020-06-01 15:11:26 +00:00
// delay(100);
}