1+ /*
2+ * Shows how to use adafruit graphics with a TFT panel and an ethernet module.
3+ * This is a 32 bit example, which by default targets 32 bit devices.
4+ * Assumed board for this is a SAMD based MKR board.
5+ *
6+ * Getting started: https://www.thecoderscorner.com/products/arduino-libraries/tc-menu/tcmenu-overview-quick-start/
7+ *
8+ * For more details see the README.md file in this directory.
9+ */
10+
111#include " colorTftEthernet32_menu.h"
212#include < IoAbstractionWire.h>
313#include < EepromAbstractionWire.h>
1020#include " ColorEtherenetCustomDraw.h"
1121#include < tcMenuVersion.h>
1222
13- // contains the graphical widget title components.
23+ // contains the tcMenu library included graphical widget title components.
1424#include " stockIcons/wifiAndConnectionIcons16x12.h"
1525
16- /*
17- * Shows how to use adafruit graphics with a TFT panel and an ethernet module.
18- * This is a 32 bit example, which by default targets 32 bit devices.
19- * Assumed board for this is a SAMD based MKR board.
20- *
21- * Getting started: https://www.thecoderscorner.com/products/arduino-libraries/tc-menu/tcmenu-overview-quick-start/
22- *
23- * For more details see the README.md file in this directory.
24- */
25-
2626// we are going to allow control of the menu over local area network
2727// so therefore must configure ethernet..
2828byte mac[] = {
2929 0xDE , 0xAD , 0xBE , 0xEF , 0xFE , 0xED
3030};
3131
32- // and we create an analog device with enhanced range because we are using a 32bit board .
33- ArduinoAnalogDevice analogDevice ( 12 , 10 );
32+ // and we create an analog device with enhanced range because on M .
33+ ArduinoAnalogDevice& analogDevice = internalAnalogDevice( );
3434
3535// We add a title widget that shows when a user is connected to the device. Connection icons
3636// are in the standard icon set we included at the top.
@@ -66,9 +66,12 @@ void onCommsChange(CommunicationInfo info) {
6666}
6767
6868void setup () {
69+ // This example logs using IoLogging, see the following guide to enable
70+ // https://www.thecoderscorner.com/products/arduino-libraries/io-abstraction/arduino-logging-with-io-logging/
71+ IOLOG_START_SERIAL
72+
6973 // we used an i2c device (io8574) so must initialise wire too
7074 Wire.begin ();
71- Serial.begin (115200 );
7275
7376 // here we make all menu items except menu voltage wrap around. Wrap means that when the value hits maximum it
7477 // goes back to 0, and when it hits 0 it goes back to maximum. Default is all wrapping off.
@@ -120,9 +123,14 @@ void setup() {
120123 // register the custom drawing handler
121124 renderer.setCustomDrawingHandler (&myCustomDraw);
122125
123- ioDevicePinMode (switches.getIoAbstraction (), ledPin, OUTPUT);
126+ // set the LED pin that we control as output
127+ switches.getIoAbstraction ()->pinMode (ledPin, OUTPUT);
124128
129+ // we can register call back that is called when the main menu title is pressed, in this case we just show
130+ // the tcMenu version number in a dialog.
125131 setTitlePressedCallback ([](int id) {
132+ // withMenuDialogIfAvailable checks if the dialog can be presented now, and if so will call the function
133+ // provided with the dialog as the parameter. you then just prepare the dialog to be shown.
126134 withMenuDialogIfAvailable ([](MenuBasedDialog* dlg) {
127135 dlg->setButtons (BTNTYPE_CLOSE, BTNTYPE_NONE);
128136 dlg->showRam (" ARM Example" , false );
@@ -132,7 +140,6 @@ void setup() {
132140 });
133141 });
134142
135- // Start 2nd encoder
136143 Serial.println (" Setting up second encoder now" );
137144
138145 // here we want the encoder set to the range of values that menuCurrent takes, this is just for example,
@@ -147,7 +154,7 @@ void setup() {
147154 // it will repeat at 25 * 20 millis before acceleration kicks in.
148155 switches.addSwitch (encoder2Click, [](pinid_t pin, bool held) {
149156 menuPwrDelay.setBoolean (!menuPwrDelay.getBoolean ());
150- ioDeviceDigitalWriteS ( switches.getIoAbstraction (), ledPin, menuPwrDelay.getBoolean ());
157+ switches.getIoAbstraction ()-> digitalWriteS ( ledPin, menuPwrDelay.getBoolean ());
151158 }, 25 );
152159 // End 2nd encoder
153160}
@@ -157,9 +164,11 @@ void loop() {
157164}
158165
159166void writeToDac () {
167+ // here we show how to convert analog menu items into floating point values
160168 float volts = menuVoltage.getAsFloatingPointValue ();
161169 float curr = menuCurrent.getAsFloatingPointValue ();
162-
170+
171+ // and now we set the output voltage of A0 using a float between 0..1
163172 float total = (volts / 64 .0F ) * (curr / 2 .0F );
164173 analogDevice.setCurrentFloat (A0, total);
165174 menuVoltA0.setFloatValue (total);
0 commit comments