Advertisement
Guest User

arduino

a guest
Feb 18th, 2016
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "U8glib.h"
  2. #include <stdlib.h>
  3.  
  4. U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE | U8G_I2C_OPT_DEV_0);    // I2C / TWI
  5.  
  6. void drawGrid(void) {
  7.   u8g.setFont(u8g_font_unifont);
  8.   for (int i = 0; i < 10; i++)
  9.   {
  10.     for (int j = 0; j < 10; j++)
  11.     {
  12.       u8g.drawStr(0, 0, "@");
  13.     }
  14.   }
  15.  
  16. }
  17. void setup(void) {
  18.   // flip screen, if required
  19.   // u8g.setRot180();
  20.  
  21.   // set SPI backup if required
  22.   //u8g.setHardwareBackup(u8g_backup_avr_spi);
  23.  
  24.   // assign default color value
  25.   if ( u8g.getMode() == U8G_MODE_R3G3B2 ) {
  26.     u8g.setColorIndex(255);     // white
  27.   }
  28.   else if ( u8g.getMode() == U8G_MODE_GRAY2BIT ) {
  29.     u8g.setColorIndex(3);         // max intensity
  30.   }
  31.   else if ( u8g.getMode() == U8G_MODE_BW ) {
  32.     u8g.setColorIndex(1);         // pixel on
  33.   }
  34.   else if ( u8g.getMode() == U8G_MODE_HICOLOR ) {
  35.     u8g.setHiColorByRGB(255, 255, 255);
  36.   }
  37.   Serial.begin(9600);
  38. }
  39. void draw(char nums[4]) {
  40.   // graphic commands to redraw the complete screen should be placed here
  41.   //u8g.setFont(u8g_font_helvB12);
  42.   u8g.setFont(u8g_font_fub30);
  43.   u8g.drawStr( 30, 40, nums);
  44.   u8g.setFont(u8g_font_profont17);
  45.   u8g.drawStr(35, 55, "km/h");
  46. }
  47. void loop(void) {
  48.   char nums[4];
  49.   8g.firstPage();
  50.   do {
  51.     if (Serial.available())
  52.     {
  53.       Serial.readBytesUntil('#', nums, 4);
  54.       nums[3] = '\0';
  55.       draw(nums);
  56.     }
  57.   } while ( u8g.nextPage() );
  58.  
  59.   // rebuild the picture after some delay
  60.   // nope - MrOsamaful
  61.  
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement