1919const int analogInputPin = A0;
2020const int pwmOutputPin = 2 ;
2121
22- // We work with analog input and output here, so we use an analog device to make it easier. It provides the ability
23- // to treat analog values as floats between 0..1 on any supported platform.
24- ArduinoAnalogDevice analogDevice;
25-
2622// We create a class extending Executable for the temprature, humidity, and pressure sensors that are built in
2723SensorManager sensorManager;
2824
@@ -35,8 +31,8 @@ void setup() {
3531 Wire.setClock (400000 );
3632
3733 // First we set up the analog pins
38- analogDevice .initPin (pwmOutputPin, DIR_OUT);
39- analogDevice .initPin (analogInputPin, DIR_IN);
34+ internalAnalogDevice () .initPin (pwmOutputPin, DIR_OUT);
35+ internalAnalogDevice () .initPin (analogInputPin, DIR_IN);
4036
4137 // Here we tell the encoder not to wrap (we don't technically need to do this as false is the default.
4238 // Wrap means go from maxValue back to 0, or from 0 back to maxValue. On is true, Off (default) is false.
@@ -50,9 +46,14 @@ void setup() {
5046 // then we initialise our sensor and motion detection and register with task manager.
5147 sensorManager.initialise ();
5248 motionDetection.initialise ();
49+
50+ // see the task manager documentation: https://www.thecoderscorner.com/products/arduino-libraries/taskmanager-io/
5351 taskManager.registerEvent (&motionDetection);
5452 taskManager.scheduleFixedRate (1 , &sensorManager, TIME_SECONDS);
5553
54+ // we can register call back that is called when the main menu title is pressed, in this case we just show
55+ // the tcMenu version number in a dialog.
56+ // https://www.thecoderscorner.com/products/arduino-libraries/tc-menu/rendering-with-tcmenu-lcd-tft-oled/#presenting-a-dialog-to-the-user
5657 setTitlePressedCallback ([](int id) {
5758 withMenuDialogIfAvailable ([](MenuBasedDialog* dlg) {
5859 dlg->setButtons (BTNTYPE_CLOSE, BTNTYPE_NONE);
@@ -65,7 +66,7 @@ void setup() {
6566
6667 // lastly we set up something simple to read from analog in
6768 taskManager.scheduleFixedRate (100 , [] {
68- menuAnalogReadingsInA0.setFloatValue (analogDevice .getCurrentFloat (analogInputPin));
69+ menuAnalogReadingsInA0.setFloatValue (internalAnalogDevice () .getCurrentFloat (analogInputPin));
6970 });
7071}
7172
@@ -74,8 +75,9 @@ void loop() {
7475 taskManager.runLoop ();
7576}
7677
77- // And something to change the PWM output when the PWM menu item changes
7878void CALLBACK_FUNCTION onPWMChanged (int id) {
79+ // here we are notified of changes in the PWM menu item and we convert that change to a value between 0 and 1.
7980 auto newPwm = menuAnalogReadingsOutputPWM.getCurrentValue () / 100 .0F ;
80- analogDevice.setCurrentFloat (pwmOutputPin, newPwm);
81+ // then we can apply that to the output pin, analogDevice does all the conversion work for us.
82+ internalAnalogDevice ().setCurrentFloat (pwmOutputPin, newPwm);
8183}
0 commit comments