#include //Include terminal library retroTerm terminal; //Create a terminal instance uint8_t buttonId = 0; //Record the button ID globally uint32_t i = 0; //Record the number of clicks uint16_t colors[] = {COLOR_RED, COLOR_GREEN, COLOR_YELLOW, COLOR_BLUE,COLOR_MAGENTA, COLOR_CYAN, COLOR_WHITE}; uint8_t red = 0; uint8_t green = 0; uint8_t blue = 0; char brush = '.'; #include // // globals // #define numpixels 1 #define pixelpower 11 #define pixelpin 12 #define bufsize 25 char buf[bufsize]; int count=0; // // setup // Adafruit_NeoPixel pixel(numpixels,pixelpin,NEO_GRB+NEO_KHZ800); void setup() { Serial.begin(115200); //Initialise the Serial stream pixel.begin(); pinMode(pixelpower,OUTPUT); digitalWrite(pixelpower,HIGH); terminal.begin(Serial); //Initialise the library uint32_t timeout = millis(); while(millis() - timeout < 30000ul && not terminal.keyPressed()) { terminal.houseKeeping(); } terminal.eraseScreen(); //Clear the screen terminal.hideCursor(); //Hide the terminal cursor terminal.enableMouse(); //Capture the mouse so it can be used with widgets terminal.setScrollWindow(4,12); //Set up somewhere to show the events without disrupting the button buttonId = terminal.newButton(1, 1, 15, 3, F("Change color"), COLOUR_GREEN, OUTER_BOX | BOX_SINGLE_LINE); //Create a green button in a box terminal.widgetShortcutKey(buttonId,f1Pressed); //Assign a shortcut key of F1 terminal.showWidget(buttonId); //Make the button visible, all widgets start 'invisible' for later display terminal.moveCursorTo(1,terminal.lines()); red = terminal.newRadioButton(terminal.columns()/3 - 1, 15, 16, 5, F("."), COLOUR_WHITE, OUTER_BOX | SHORTCUT_INLINE); //Create three new widgets and record the IDs green = terminal.newRadioButton(terminal.columns()/3, 17, 14, 1, F("X"), COLOUR_WHITE, SHORTCUT_INLINE); //The method returns 0 if it fails blue = terminal.newRadioButton(terminal.columns()/3, 18, 14, 1, F("O"), COLOUR_WHITE, SHORTCUT_INLINE); //Colour is the colour of the frame, lettering can be different if(red) { terminal.labelAttributes(red, COLOUR_RED | ATTRIBUTE_BRIGHT); //Make the label text more emphasised, for better contrast terminal.showWidget(red); //Make this button visible terminal.widgetShortcutKey(red,f7Pressed); terminal.widgetValue(red,true); //Make this button selected at the start. All visible radio buttons are in a single group } if(green) { terminal.labelAttributes(green, COLOUR_GREEN | ATTRIBUTE_BRIGHT); //Make the label text more emphasised, for better contrast terminal.showWidget(green); //Make this button visible terminal.widgetShortcutKey(green,f8Pressed); } if(blue) { terminal.labelAttributes(blue, COLOUR_BLUE | ATTRIBUTE_BRIGHT); //Make the label text more emphasised, for better contrast terminal.showWidget(blue); //Make this button visible terminal.widgetShortcutKey(blue,f9Pressed); } } void loop() { terminal.houseKeeping(); if(terminal.widgetClicked(buttonId)) //This clears the 'click' on checking { i++; if(i>6){ i = 0; } switch(i) { // Start the new animation... case 0: pixel.setPixelColor(0,pixel.Color(255,0, 0)); pixel.show(); // Red break; case 1: pixel.setPixelColor(0,pixel.Color(0,255,0)); pixel.show(); // Green break; case 2: pixel.setPixelColor(0,pixel.Color(255,255,0)); pixel.show(); // Yellow break; case 3: pixel.setPixelColor(0,pixel.Color(0,0,255)); pixel.show(); // Blue break; case 4: pixel.setPixelColor(0,pixel.Color(255,0, 255)); pixel.show(); // Magenta break; case 5: pixel.setPixelColor(0,pixel.Color(0,255,255)); pixel.show(); // Cyan break; case 6: pixel.setPixelColor(0,pixel.Color(255,255,255)); pixel.show(); // White break; } } if(terminal.mouseButtonDown()) { terminal.foregroundColour(colors[i]); terminal.printAt(terminal.mouseColumn(),terminal.mouseRow(),brush); } if(terminal.widgetClicked(red)) { if(terminal.widgetValue(red)) { brush = '.'; } } if(terminal.widgetClicked(green)) { if(terminal.widgetValue(green)) { brush = 'X'; } } if(terminal.widgetClicked(blue)) { if(terminal.widgetValue(blue)) { brush = 'O'; } } terminal.houseKeeping(); //You MUST run housekeeping to show any changes! }