Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: Adafruit-GFX-Library-master Adafruit-GP9002-Grayscale-VFD-Library mbed
Fork of GP9002adafruit by
GraphicVFDtest.cpp
00001 #include <SPI.h> 00002 #include "Adafruit_GFX.h" 00003 #include "Adafruit_GP9002.h" 00004 00005 #define _MOSI p5 // VFD PIN#12 00006 #define _MISO p6 // VFD PIN#8 00007 #define _CLK p7 // VFD PIN#11 00008 #define _CS p8 // VFD PIN#13 00009 #define _DC p22 // VFD PIN#14 00010 // connect VFD #15, #16, #17 to 5V 00011 // connect VFD #9 #18 #19 #20 to ground 00012 SPI SPIport(_MOSI,_MISO,_CLK); 00013 Adafruit_GP9002 display = Adafruit_GP9002(SPIport, _CS, _DC); 00014 00015 // if using hardware SPI on an UNO or other classic Arduino, the pinouts are the same as 00016 // above. 00017 //Adafruit_GP9002 display = Adafruit_GP9002(_CS, _DC); 00018 00019 #ifndef min 00020 #define min(a,b) ((a)<(b)?(a):(b)) 00021 #endif 00022 #ifndef max 00023 #define max(a,b) ((a)>(b)?(a):(b)) 00024 #endif 00025 00026 00027 #define NUMFLAKES 10 00028 #define XPOS 0 00029 #define YPOS 1 00030 #define DELTAY 2 00031 00032 00033 #define LOGO16_GLCD_HEIGHT 16 00034 #define LOGO16_GLCD_WIDTH 16 00035 const unsigned char logo16_glcd_bmp[] = 00036 { 0b00000000, 0b11000000, 00037 0b00000001, 0b11000000, 00038 0b00000001, 0b11000000, 00039 0b00000011, 0b11100000, 00040 0b11110011, 0b11100000, 00041 0b11111110, 0b11111000, 00042 0b01111110, 0b11111111, 00043 0b00110011, 0b10011111, 00044 0b00011111, 0b11111100, 00045 0b00001101, 0b01110000, 00046 0b00011011, 0b10100000, 00047 0b00111111, 0b11100000, 00048 0b00111111, 0b11110000, 00049 0b01111100, 0b11110000, 00050 0b01110000, 0b01110000, 00051 0b00000000, 0b00110000 }; 00052 00053 #include "adabmp.c" 00054 00055 extern const unsigned char BitReverseTable256[]; 00056 00057 00058 void testdrawbitmap(const uint8_t *bitmap, uint8_t w, uint8_t h) { 00059 uint8_t icons[NUMFLAKES][3]; 00060 srand(666); // whatever seed 00061 00062 // initialize 00063 for (uint8_t f=0; f< NUMFLAKES; f++) { 00064 icons[f][XPOS] = rand() % display.width(); 00065 icons[f][YPOS] = 0; 00066 icons[f][DELTAY] = rand() % 5 + 1; 00067 00068 /* Serial.print("x: "); 00069 Serial.print(icons[f][XPOS], DEC); 00070 Serial.print(" y: "); 00071 Serial.print(icons[f][YPOS], DEC); 00072 Serial.print(" dy: "); 00073 Serial.println(icons[f][DELTAY], DEC); 00074 */ } 00075 00076 while (1) { 00077 // draw each icon 00078 for (uint8_t f=0; f< NUMFLAKES; f++) { 00079 display.drawBitmap(icons[f][XPOS], icons[f][YPOS], logo16_glcd_bmp, w, h, WHITE); 00080 } 00081 wait_ms(200); 00082 00083 // then erase it + move it 00084 for (uint8_t f=0; f< NUMFLAKES; f++) { 00085 display.drawBitmap(icons[f][XPOS], icons[f][YPOS], logo16_glcd_bmp, w, h, BLACK); 00086 // move it 00087 icons[f][YPOS] += icons[f][DELTAY]; 00088 // if its gone, reinit 00089 if (icons[f][YPOS] > display.height()) { 00090 icons[f][XPOS] = rand() % display.width(); 00091 icons[f][YPOS] = 0; 00092 icons[f][DELTAY] = rand() % 5 + 1; 00093 } 00094 } 00095 } 00096 } 00097 00098 00099 void testdrawchar(void) { 00100 display.setTextSize(1); 00101 display.setTextColor(WHITE); 00102 display.setCursor(0,0); 00103 00104 for (uint8_t i=0; i < 168; i++) { 00105 if (i == '\n') continue; 00106 display.putc(i); 00107 //if ((i > 0) && (i % 14 == 0)) 00108 //display.println(); 00109 } 00110 } 00111 00112 void testdrawcircle(void) { 00113 for (uint8_t i=0; i<display.height(); i+=2) { 00114 display.drawCircle(display.width()/2, display.height()/2, i, WHITE); 00115 } 00116 } 00117 00118 void testfillrect(void) { 00119 uint8_t color = 1; 00120 for (uint8_t i=0; i<display.height()/2; i+=3) { 00121 // alternate colors 00122 display.fillRect(i, i, display.width()-i*2, display.height()-i*2, color%4); 00123 color++; 00124 } 00125 } 00126 00127 void testdrawtriangle(void) { 00128 for (int16_t i=0; i<min(display.width(),display.height())/2; i+=5) { 00129 display.drawTriangle(display.width()/2, display.height()/2-i, 00130 display.width()/2-i, display.height()/2+i, 00131 display.width()/2+i, display.height()/2+i, WHITE); 00132 } 00133 } 00134 00135 void testfilltriangle(void) { 00136 uint8_t color = 3; 00137 for (int16_t i=min(display.width(),display.height())/2; i>0; i-=5) { 00138 display.fillTriangle(display.width()/2, display.height()/2-i, 00139 display.width()/2-i, display.height()/2+i, 00140 display.width()/2+i, display.height()/2+i, color); 00141 if (color) color--; 00142 else color = 3; 00143 } 00144 } 00145 00146 void testdrawroundrect(void) { 00147 for (uint8_t i=2; i<display.height()/4; i+=2) { 00148 display.drawRoundRect(i, i, display.width()-2*i, display.height()-2*i, display.height()/4, 3); 00149 } 00150 } 00151 00152 void testfillroundrect(void) { 00153 uint8_t color = WHITE; 00154 for (uint8_t i=0; i<display.height()/4-2; i+=2) { 00155 display.fillRoundRect(i, i, display.width()-2*i, display.height()-2*i, display.height()/4, color); 00156 if (color) color--; 00157 else color = 3; 00158 } 00159 } 00160 00161 void testdrawrect(void) { 00162 for (uint8_t i=0; i<display.height()/2; i+=2) { 00163 display.drawRect(i, i, display.width()-2*i, display.height()-2*i, WHITE); 00164 } 00165 } 00166 00167 void testdrawline() { 00168 for (uint8_t i=0; i<display.width(); i+=4) { 00169 display.drawLine(0, 0, i, display.height()-1, WHITE); 00170 } 00171 for (uint8_t i=0; i<display.height(); i+=4) { 00172 display.drawLine(0, 0, display.width()-1, i, WHITE); 00173 } 00174 wait_ms(250); 00175 00176 display.clearDisplay(); 00177 for (uint8_t i=0; i<display.width(); i+=4) { 00178 display.drawLine(0, display.height()-1, i, 0, WHITE); 00179 } 00180 for (int8_t i=display.height()-1; i>=0; i-=4) { 00181 display.drawLine(0, display.height()-1, display.width()-1, i, WHITE); 00182 } 00183 wait_ms(250); 00184 00185 display.clearDisplay(); 00186 for (int8_t i=display.width()-1; i>=0; i-=4) { 00187 display.drawLine(display.width()-1, display.height()-1, i, 0, WHITE); 00188 } 00189 for (int8_t i=display.height()-1; i>=0; i-=4) { 00190 display.drawLine(display.width()-1, display.height()-1, 0, i, WHITE); 00191 } 00192 wait_ms(250); 00193 00194 display.clearDisplay(); 00195 for (uint8_t i=0; i<display.height(); i+=4) { 00196 display.drawLine(display.width()-1, 0, 0, i, WHITE); 00197 } 00198 for (uint8_t i=0; i<display.width(); i+=4) { 00199 display.drawLine(display.width()-1, 0, i, display.height()-1, WHITE); 00200 } 00201 wait_ms(250); 00202 } 00203 00204 int main() { 00205 // Serial.begin(9600); 00206 00207 display.begin(); 00208 // init done 00209 00210 // wait_ms(2000); 00211 // display.clearDisplay(); // clears the screen and buffer redundant 00212 /* 00213 display.drawPixel(10, 10, WHITE); 00214 display.drawPixel(20, 20, WHITE); 00215 wait_ms(2000); 00216 00217 display.clearDisplay(); 00218 00219 // draw many lines 00220 testdrawline(); 00221 delay(2000); 00222 display.clearDisplay(); 00223 // draw rectangles 00224 testdrawrect(); 00225 delay(2000); 00226 display.clearDisplay(); 00227 00228 // draw multiple rectangles 00229 testfillrect(); 00230 delay(2000); 00231 display.clearDisplay(); 00232 00233 // draw mulitple circles 00234 testdrawcircle(); 00235 delay(2000); 00236 display.clearDisplay(); 00237 */ 00238 00239 // draw a circle, 10 pixel radius 00240 display.fillCircle(20, 20, 20, WHITE); 00241 wait_ms(2000); 00242 00243 display.clearDisplay(); 00244 testdrawroundrect(); 00245 wait_ms(2000); 00246 display.clearDisplay(); 00247 00248 testfillroundrect(); 00249 wait_ms(2000); 00250 display.clearDisplay(); 00251 00252 testdrawtriangle(); 00253 wait_ms(2000); 00254 display.clearDisplay(); 00255 00256 testfilltriangle(); 00257 wait_ms(2000); 00258 display.clearDisplay(); 00259 00260 // draw the first ~12 characters in the font 00261 testdrawchar(); 00262 wait_ms(2000); 00263 display.clearDisplay(); 00264 00265 // text display tests 00266 display.setTextSize(1); 00267 display.setTextColor(WHITE); 00268 display.setCursor(0,0); 00269 display.printf("Hello, world!\n"); 00270 display.setTextColor(BLACK, WHITE); // 'inverted' text 00271 display.printf("%f",3.141592); 00272 display.setTextSize(2); 00273 display.setTextColor(WHITE); 00274 display.printf("0x%8x",0xDEADBEEF); 00275 wait_ms(2000); 00276 00277 // miniature bitmap display 00278 display.clearDisplay(); 00279 display.drawBitmap(30, 16, logo16_glcd_bmp, 16, 16, 1); 00280 00281 wait_ms(2000); 00282 display.clearDisplay(); 00283 /* display.command(GP9002_ADDRINCR); 00284 display.command(GP9002_ADDRL); 00285 display.dataWrite(0x00); 00286 display.command(GP9002_ADDRH); 00287 display.dataWrite(0x00); 00288 display.command(GP9002_DATAWRITE); 00289 */ 00290 int x=0; 00291 int y; 00292 int byte; 00293 for(uint32_t count2=0; count2<128; count2++) { 00294 y=0; 00295 for(uint32_t count=count2; count<0x400; count+=128) { 00296 byte=adabmp[count]; 00297 for(int count3=0; count3<8;count3++) { 00298 if (byte & 0x01) display.drawPixel(x,y,WHITE); 00299 byte >>=1; 00300 y++; 00301 } 00302 } 00303 x++; 00304 } 00305 00306 } 00307 00308 00309 void loop() { 00310 00311 }
Generated on Thu Jul 14 2022 13:06:32 by
1.7.2
