Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // DebugHardware.h
- #ifndef _DEBUGHARDWARE_h
- #define _DEBUGHARDWARE_h
- #include <arduino.h>
- /*********************************************************************************
- * Input:
- * Px --> Select Pin x
- * Ax --> Select Analog x
- * I --> Input
- * O --> Output
- * ? --> Query level
- * l --> Set low
- * h --> Set high
- * v --> Query analog value
- *
- ********************************************************************************/
- class DebugHardware
- {
- protected:
- byte pin;
- public:
- bool handle ();
- bool handle (const char* action);
- };
- #endif
- ********************************************************************************
- // DebugHardware.cpp
- #include "DebugHardware.h"
- bool DebugHardware::handle ()
- {
- if (!Serial.available ())
- return false;
- char bfr[8];
- Serial.readBytesUntil ('\n', bfr, sizeof (bfr));
- return handle (bfr);
- }
- bool DebugHardware::handle (const char* action)
- {
- switch (*action)
- {
- case 'P':
- pin = atoi (action + 1);
- Serial.print (F ("Pin "));
- Serial.print (pin);
- Serial.println ();
- return true;
- case 'A':
- pin = PIN_A0 + atoi (action + 1);
- Serial.print (F ("Analog "));
- Serial.print (pin);
- Serial.println ();
- return true;
- case 'I':
- pinMode (pin, INPUT);
- Serial.println (F ("INPUT"));
- return true;
- case 'U':
- pinMode (pin, INPUT_PULLUP);
- Serial.println (F ("PULLUP"));
- return true;
- case 'O':
- pinMode (pin, OUTPUT);
- Serial.println (F ("OUTPUT"));
- return true;
- case '?':
- Serial.println (digitalRead (pin) ? F ("High") : F ("Low"));
- return true;
- case 'l':
- digitalWrite (pin, LOW);
- Serial.println (F ("Low"));
- return true;
- case 'h':
- digitalWrite (pin, HIGH);
- Serial.println (F ("High"));
- return true;
- case 'v':
- {
- auto value = analogRead (pin);
- Serial.println (value);
- return true;
- }
- default:
- Serial.println (F ("Px, I/U/O, ?, l/h, v:"));
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement