diff --git a/MicroView.cpp b/MicroView.cpp index 10488fd..0ce324f 100644 --- a/MicroView.cpp +++ b/MicroView.cpp @@ -1419,17 +1419,29 @@ size_t MicroView::write(uint8_t c) { /** \brief MicroViewSlider class initialisation with style. - Initialise the MicroViewSlider widget with style WIDGETSTYLE0 or WIDGETSTYLE1. + Initialise the MicroViewSlider widget with style WIDGETSTYLE0 or WIDGETSTYLE1 or WIDGETSTYLE2 (like 0, but vertical) or WIDGETSTYLE3 (like 1, but vertical). If this list gets any longer, it might be better as a switch/case statement. */ MicroViewSlider::MicroViewSlider(uint8_t newx, uint8_t newy, int16_t min, int16_t max, uint8_t sty):MicroViewWidget(newx, newy, min, max) { if (sty==WIDGETSTYLE0) { style=0; totalTicks=30; } - else { + else if (sty==WIDGETSTYLE1) { style=1; totalTicks=60; } + else if (sty==WIDGETSTYLE2) { + style=2; + totalTicks=20; + } + else if (sty==WIDGETSTYLE3) { + style=3; + totalTicks=40; + } + else { //unrecognized style, so use default + style=0; + totalTicks=30; + } needFirstDraw=true; prevValue=getMinValue(); @@ -1446,31 +1458,39 @@ size_t MicroView::write(uint8_t c) { offsetX=getX(); offsetY=getY(); - if(style>0) - majorLine=7; - else - majorLine=4; - - // Draw major tickers - for (uint8_t i=0; i0) { - for (uint8_t i=0; i<4;i++) { - uView.lineV(offsetX+33+(i*2), offsetY+5, 3); + if(style==0) + majorLine=4; + else if (style==1) + majorLine=7; + else if (style==2) + majorLine=3; + else if (style==3) + majorLine=5; + + + +//Horizontal styles, style 0 or 1 + + if (style==0 || style==1) { + // Draw major tickers + for (uint8_t i=0; i0) { + // Draw minor tickers + for (uint8_t i=0; i<4;i++) { + uView.lineV(offsetX+3+(i*2), offsetY+5, 3); + } + for (uint8_t i=0; i<4;i++) { + uView.lineV(offsetX+13+(i*2), offsetY+5, 3); + } + for (uint8_t i=0; i<4;i++) { + uView.lineV(offsetX+23+(i*2), offsetY+5, 3); + } + + if(style==1) { //Longer line, more minor ticks + for (uint8_t i=0; i<4;i++) { + uView.lineV(offsetX+33+(i*2), offsetY+5, 3); + } for (uint8_t i=0; i<4;i++) { uView.lineV(offsetX+43+(i*2), offsetY+5, 3); } @@ -1479,6 +1499,31 @@ size_t MicroView::write(uint8_t c) { } } } +//Vertical styles, style 2 or 3 + else { + // Draw major tickers + for (uint8_t i=0; i0) - uView.setCursor(offsetX,offsetY+10); - else - uView.setCursor(offsetX+34,offsetY+1); + if(style==0) + uView.setCursor(offsetX+34,offsetY+1); + else if (style==1) + uView.setCursor(offsetX,offsetY+10); + else if (style==2) + uView.setCursor(offsetX+1,offsetY+24); + else //style==3 + uView.setCursor(offsetX+9,offsetY); + uView.print(strBuffer); } @@ -1642,7 +1713,7 @@ size_t MicroView::write(uint8_t c) { } // ------------------------------------------------------------------------------------- - // Slider Widget - end + // Gauge Widget - end // ------------------------------------------------------------------------------------- /** \brief SPI Initialisation. diff --git a/MicroView.h b/MicroView.h index 4a93ab2..e0ee151 100644 --- a/MicroView.h +++ b/MicroView.h @@ -78,6 +78,8 @@ #define WIDGETSTYLE0 0 #define WIDGETSTYLE1 1 #define WIDGETSTYLE2 2 +//Added for Vertical slider styles +#define WIDGETSTYLE3 3 #define SETCONTRAST 0x81 #define DISPLAYALLONRESUME 0xA4 diff --git a/keywords.txt b/keywords.txt index a10e127..da714d1 100644 --- a/keywords.txt +++ b/keywords.txt @@ -77,5 +77,6 @@ ALL LITERAL1 WIDGETSTYLE0 LITERAL1 WIDGETSTYLE1 LITERAL1 WIDGETSTYLE2 LITERAL1 +WIDGETSTYLE3 LITERAL1 diff --git a/vert_slider_test.ino b/vert_slider_test.ino new file mode 100644 index 0000000..e491de2 --- /dev/null +++ b/vert_slider_test.ino @@ -0,0 +1,47 @@ +#include + +int buttonPin = A0; // push button pin +int buttonState = 0; // variable for reading the pushbutton status +int onCount = 0; +MicroViewWidget *hWidget, *vWidget1, *vWidget2; + +void setup() { + uView.begin(); + uView.clear(PAGE); + + // initialize the pushbutton pin as an input: + pinMode(buttonPin, INPUT); + digitalWrite(buttonPin,HIGH); + + //Create a slider to count how long the switch is on +// hWidget = new MicroViewSlider(0, 0, 0, 99, WIDGETSTYLE0); + vWidget1 = new MicroViewSlider(0, 0, 0, 255, WIDGETSTYLE2); + vWidget2 = new MicroViewSlider(31, 0, 0, 255, WIDGETSTYLE3); +} + +void loop() { + // read the state of the pushbutton value: + buttonState = digitalRead(buttonPin); + + // check if the pushbutton is pressed. + // if it is not pressed, the buttonState is HIGH: + if (buttonState == HIGH) { + onCount = min(onCount+1, 255); +// hWidget->setValue(onCount); + vWidget1->setValue(onCount); + vWidget2->setValue(onCount); +// uView.setCursor(0,0); +// uView.print("OFF"); + uView.display(); + } + else { + onCount = max(onCount-1, 0); +// hWidget->setValue(onCount); + vWidget1->setValue(onCount); + vWidget2->setValue(onCount); +// uView.setCursor(0,0); +// uView.print("ON "); + uView.display(); + } +} +