Exemple #1
0
void testdrawbitmap(const uint8_t *bitmap, uint8_t w, uint8_t h) {
  uint8_t icons[NUMFLAKES][3];

  // initialize
  for (uint8_t f=0; f< NUMFLAKES; f++) {
    icons[f][XPOS] = rand()%display.width();
    icons[f][YPOS] = 0;
    icons[f][DELTAY] = rand()%(5) + 1;
  }

  while (1) {
    // draw each icon
    for (uint8_t f=0; f< NUMFLAKES; f++) {
      display.drawBitmap(icons[f][XPOS], icons[f][YPOS], logo16_glcd_bmp, w, h, WHITE);
    }
    display.display();
    delay(20);

    // then erase it + move it
    for (uint8_t f=0; f< NUMFLAKES; f++) {
      display.drawBitmap(icons[f][XPOS], icons[f][YPOS],  logo16_glcd_bmp, w, h, BLACK);
      // move it
      icons[f][YPOS] += icons[f][DELTAY];
      // if its gone, reinit
      if (icons[f][YPOS] > display.height()) {
	icons[f][XPOS] = rand()%(display.width());
	icons[f][YPOS] = 0;
	icons[f][DELTAY] = rand()%(5) + 1;
      }
    }
   }
}
Exemple #2
0
void testdrawtriangle(void) {
  for (int16_t i=0; i<min(display.width(),display.height())/2; i+=5) {
    display.drawTriangle(display.width()/2, display.height()/2-i,
                     display.width()/2-i, display.height()/2+i,
                     display.width()/2+i, display.height()/2+i, WHITE);
    display.display();
  }
}
Exemple #3
0
void testfilltriangle(void) {
  uint8_t color = BLACK;
  for (int16_t i=min(display.width(),display.height())/2; i>0; i-=5) {
    display.fillTriangle(display.width()/2, display.height()/2-i,
                     display.width()/2-i, display.height()/2+i,
                     display.width()/2+i, display.height()/2+i, color);
    if (color == WHITE) color = BLACK;
    else color = WHITE;
    display.display();
  }
}
Exemple #4
0
int main(int argc, char **argv)
{
  float soil = 65.5;
  float temp = 5.5;

	// I2C change parameters to fit to your LCD
	if ( !display.init(OLED_I2C_RESET,OLED_ADAFRUIT_I2C_128x64) )
		exit(EXIT_FAILURE);

	display.begin();
	
	// init done
	display.clearDisplay();   // clears the screen and buffer

  // text display tests
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0,0);
  display.print("     XBee Messung\n");
  display.drawLine(0, 10, display.width()-1, 10, WHITE);
  display.setCursor(0,15);
  display.printf("Bodenfeuchte: %4.1f %%\n", soil);
  display.printf("Temperatur:   %4.1f C\n\n\n", temp);
  if(soil > 50) {
    display.print("--> Feucht genug\n");
  } else {
    display.print("--> Zu Trocken! \n");
  }
  
  display.display();

  // Free PI GPIO ports
  display.close();
}
Exemple #5
0
void testfillrect(void) {
  uint8_t color = 1;
  for (int16_t i=0; i<display.height()/2; i+=3) {
    // alternate colors
    display.fillRect(i, i, display.width()-i*2, display.height()-i*2, color%2);
    display.display();
    color++;
  }
}
Exemple #6
0
void testfillroundrect(void) {
  uint8_t color = BLACK;
  for (int16_t i=0; i<display.height()/2-2; i+=2) {
    display.fillRoundRect(i, i, display.width()-2*i, display.height()-2*i, display.height()/4, color);
    if (color == WHITE) color = BLACK;
    else color = WHITE;
    display.display();
  }
}
Exemple #7
0
void testdrawline() {
  for (int16_t i=0; i<display.width(); i+=4) {
    display.drawLine(0, 0, i, display.height()-1, WHITE);
    display.display();
  }
  for (int16_t i=0; i<display.height(); i+=4) {
    display.drawLine(0, 0, display.width()-1, i, WHITE);
    display.display();
  }
  delay(25);

  display.clearDisplay();
  for (int16_t i=0; i<display.width(); i+=4) {
    display.drawLine(0, display.height()-1, i, 0, WHITE);
    display.display();
  }
  for (int8_t i=display.height()-1; i>=0; i-=4) {
    display.drawLine(0, display.height()-1, display.width()-1, i, WHITE);
    display.display();
  }
  delay(25);

  display.clearDisplay();
  for (int16_t i=display.width()-1; i>=0; i-=4) {
    display.drawLine(display.width()-1, display.height()-1, i, 0, WHITE);
    display.display();
  }
  for (int16_t i=display.height()-1; i>=0; i-=4) {
    display.drawLine(display.width()-1, display.height()-1, 0, i, WHITE);
    display.display();
  }
  delay(25);

  display.clearDisplay();
  for (int16_t i=0; i<display.height(); i+=4) {
    display.drawLine(display.width()-1, 0, 0, i, WHITE);
    display.display();
  }
  for (int16_t i=0; i<display.width(); i+=4) {
    display.drawLine(display.width()-1, 0, i, display.height()-1, WHITE);
    display.display();
  }
  delay(25);
}
void Demo1()
{
	Serial.println("Display: circle");
	// Clear the buffer.
	display.clearDisplay();
	// draw a circle, 10 pixel radius
	display.fillCircle(display.width()/2, display.height()/2, 10, WHITE);
	display.display();
	DemoTimer.stop();
	DemoTimer.initializeMs(2000, Demo2).start();	
}
Exemple #9
0
/**
   Popup input window with text centered. Window height is based on maxChars
*/
void ANXInputWindow(char * message, char *title, uint8_t maxChars) {

  uint8_t w = (display.width() * .8) + 4;
  uint8_t maxCharsPerRow = w / ANX_FONT_WIDTH;
  uint8_t rows = (maxChars / maxCharsPerRow) + 1;
  uint8_t textHeight = rows * ANX_FONT_HEIGHT;
  uint8_t h = textHeight + ANX_FONT_HEIGHT + 3 + 2;
  uint8_t x = (display.width() - w) / 2;
  uint8_t y = (display.height() - h) / 2;
  uint8_t tx = (display.width() - (ANX_FONT_WIDTH * strlen(title))) / 2;
  uint8_t ty = y + 1;

  display.fillRoundRect(x, y, w, h, 2, BLACK);
  display.drawRoundRect(x, y, w, h, 2, WHITE);
  display.fillRoundRect(x, y, w, ANX_FONT_HEIGHT + 1, 2, WHITE);

  display.setCursor(tx, ty);
  display.setTextColor(INVERSE);
  display.print(title);

  ANXInput(message, x + 2, y + ANX_FONT_HEIGHT + 3, maxChars, maxCharsPerRow);
}
Exemple #10
0
void init()
{
	Serial.begin(SERIAL_BAUD_RATE); // 115200 by default
	Serial.systemDebugOutput(true); // Allow debug output to serial

	Serial.println("Display start");
	display.begin(SSD1306_SWITCHCAPVCC);
	display.display();
	delay(2000);

	// Clear the buffer.
	display.clearDisplay();

	// draw a circle, 10 pixel radius
	display.fillCircle(display.width()/2, display.height()/2, 10, WHITE);
	display.display();
	delay(2000);
	display.clearDisplay();

	// text display tests
	display.setTextSize(1);
	display.setTextColor(WHITE);
	display.setCursor(0,0);
	display.println("Sming Framework");
	display.setTextColor(BLACK, WHITE); // 'inverted' text
	display.setCursor(104, 7);
	display.println("v1.0");
	//----
	display.setTextColor(WHITE);
	display.println("Let's do smart things");
	display.setTextSize(3);
	display.print("IoT");
	display.display();

	delay(2000);
}
Exemple #11
0
void doChat() {
  //Setup chat
  _maxCharsPerRow = (display.width() / ANX_FONT_WIDTH) - 2;
  _bottom = CHAT_MESSAGES_MAX - 1;

  uint8_t button = 0;
  uint8_t lastChatPtr = 0;
  bool quit = false;

  //Warn user then quit if radio is not available
  if (!ANXRFAvailable()) {
    statusDialog("Radio disabled");
    quit = true;
  }

  //Warn user then quit if in airplane mode
  if (ANXGetAirplane()) {
    statusDialog("Badge is in\nairplane mode");
    quit = true;
  }

  if (quit) {
    waitForButton();
    clearButtonState();
    return;
  }

  while (1) {
    _drawMessages();
    lastChatPtr = chatBufferPtr;

    //Idle handling RF and buttons
    while (chatBufferPtr == lastChatPtr && button == 0) {
      //Handle tasks
      tick();
      //Check buttons
      button = getButtonState();
    }

    //Handle button presses in one block
    //If message is null, meaning nothing was passed into doChat, then execute a normal chat entry.
    if (button > 0) {
      //Quit on left
      if (button == BUTTON_LEFT) {
        clearButtonState();
        return;
      }

      //Popup chat window on enter
      if (button == BUTTON_ENTER) {
        clearButtonState();

        //Get a
        char message[ANX_CHAT_MAX_LENGTH];
        memset(message, '\0', ANX_CHAT_MAX_LENGTH); //initialize to null before using no matter wut
        ANXInputWindow(message, mi_main_chat, ANX_CHAT_MAX_LENGTH);
        if (strlen(message) > 0) {
          ANXRFSendChat(message);
        }
      }
    }
    //cleanup
    button = 0;
  }
}
Exemple #12
0
void testdrawcircle(void) {
  for (int16_t i=0; i<display.height(); i+=2) {
    display.drawCircle(display.width()/2, display.height()/2, i, WHITE);
    display.display();
  }
}
Exemple #13
0
void test_task(void*)   {
	while(1){
		display.begin();
		//display.setContrast(50);
		display.display();

		delay(2000);
		display.clearDisplay();   // clears the screen and buffer

		// draw a single pixel
		display.drawPixel(10, 10, WHITE);
		display.display();
		delay(2000);
		display.clearDisplay();

		// draw many lines
		testdrawline();
		display.display();
		delay(2000);
		display.clearDisplay();

		// draw rectangles
		testdrawrect();
		display.display();
		delay(2000);
		display.clearDisplay();

		// draw multiple rectangles
		testfillrect();
		display.display();
		delay(2000);
		display.clearDisplay();

		// draw mulitple circles
		testdrawcircle();
		display.display();
		delay(2000);
		display.clearDisplay();

		// draw a circle, 10 pixel radius
		display.fillCircle(display.width()/2, display.height()/2, 10, WHITE);
		display.display();
		delay(2000);
		display.clearDisplay();

		testdrawroundrect();
		delay(2000);
		display.clearDisplay();

		testfillroundrect();
		delay(2000);
		display.clearDisplay();

		testdrawtriangle();
		delay(2000);
		display.clearDisplay();

		testfilltriangle();
		delay(2000);
		display.clearDisplay();

		// draw the first ~12 characters in the font
		testdrawchar();
		display.display();
		delay(2000);
		display.clearDisplay();

		// draw scrolling text
		testscrolltext();
		delay(2000);
		display.clearDisplay();

		// text display tests
		display.setTextSize(2);
		display.setTextColor(WHITE);
		display.setCursor(0,0);
		display.println((char*)"Hello, world!");
		display.setTextColor(WHITE, BLACK); // 'inverted' text
		display.println((char*)"3.141592");
		display.setTextSize(1);
		display.setTextColor(WHITE);
		display.print((char*)"0x");
		display.println((char*)"DEADBEEF");
		display.display();
		delay(2000);

		// rotation example
		display.clearDisplay();
		display.setRotation(1);  // rotate 90 degrees counter clockwise, can also use values of 2 and 3 to go further.
		display.setTextSize(1);
		display.setTextColor(WHITE);
		display.setCursor(0,0);
		display.println((char*)"Rotation");
		display.setTextSize(1);
		display.println((char*)"Example!");
		display.display();
		delay(2000);

		// revert back to no rotation
		display.setRotation(0);

		// miniature bitmap display
		display.clearDisplay();
		display.drawBitmap(30, 16,  logo16_glcd_bmp, 16, 16, WHITE);
		display.display();

		// invert the display
		display.invertDisplay(true);
		delay(1000);
		display.invertDisplay(false);
		delay(1000);

		// draw a bitmap icon and 'animate' movement
		testdrawbitmap(logo16_glcd_bmp, LOGO16_GLCD_WIDTH, LOGO16_GLCD_HEIGHT);
	}
}
Exemple #14
0
void testdrawrect(void) {
  for (int16_t i=0; i<display.height()/2; i+=2) {
    display.drawRect(i, i, display.width()-2*i, display.height()-2*i, WHITE);
    display.display();
  }
}
Exemple #15
0
/**
   Interactively accepts input from the user
   Max input size is determined by remaining cells at given start row. No scrolling.
*/
void ANXInput(char *message, uint8_t startX, uint8_t startY, uint8_t maxChars, uint8_t maxCharsPerRow) {
  int messageLen = strlen(message);             //Size of the message
  int cursor = messageLen;       //Location of cursor in the text, put cursor at end of message to continue
  uint8_t row = 0;          //Row of the cursor
  uint8_t col = 0;          //Col of the cursor
  uint8_t cindex = 0;   //index within input char array
  int maxCols = (display.width() - startX) / ANX_FONT_WIDTH;    //Max number of cols available
  int maxRows = (display.height() - startY) / ANX_FONT_HEIGHT;  //Max number of rows available
  int maxLen = min(maxCols * maxRows, maxChars);           //Maximum possible size of the message (limited by input space and buffer)

  //Use the user specified chars per row if specified
  if (maxCharsPerRow > 0) {
    maxCols = min(maxCharsPerRow, maxCols);
  }

  //Print the message, if any
  ANXInputMoveCursor(row, col, startX, startY);
  display.print(message);

  //Iteractively get input from user
  while (1) {
    row = cursor / maxCols;
    col = cursor % maxCols;

    ANXInputClearChar(row, col, startX, startY);
    ANXInputDrawCursor(row, col, startX, startY);

    if (message[cursor] != NULL) {
      ANXInputMoveCursor(row, col, startX, startY);
      display.print(message[cursor]);
    }

    safeDisplay();

    uint8_t button = waitForButton();
    if ((button & BUTTON_DOWN) > 0) {

      //Move char index to the end pro-actively since unsigned won't wrap to -1
      if (cindex == 0) cindex = INPUT_CHARS_COUNT;
      cindex--;

      if (cursor >= messageLen) {
        messageLen++;
      }
      message[cursor] = INPUT_CHARS[cindex];

      //Make sure we're not null terminating the string early
      if (cursor > 0) {
        if (message[cursor - 1] == '\0') message[cursor - 1] = ' ';
      }

      deepSleep(BUTTON_REPEAT_DELAY);
    }

    if ((button & BUTTON_UP) > 0) {
      cindex++;
      if (cindex >= INPUT_CHARS_COUNT) cindex = 0;
      if (cursor >= messageLen) {
        messageLen++;
      }
      message[cursor] = INPUT_CHARS[cindex];

      //Make sure we're not null terminating the string early
      if (cursor > 0) {
        if (message[cursor - 1] == '\0') message[cursor - 1] = ' ';
      }

      deepSleep(BUTTON_REPEAT_DELAY);
    }

    if ((button & BUTTON_RIGHT) > 0) {
      ANXInputDrawCursor(row, col, startX, startY);

      //Prevent cursor from going off the deep end
      if (cursor < maxLen - 1) {
        cursor++;
      }

      if (cursor < messageLen) {
        cindex = ANXIndexOf(INPUT_CHARS, message[cursor]);
      } else {
        messageLen++;
        cindex = 0;
      }

      //Make sure we're not null terminating the string early
      if (cursor > 0) {
        if (message[cursor - 1] == '\0') message[cursor - 1] = ' ';
      }

      //Don't allow repeats
      clearButtonState();
    }

    if ((button & BUTTON_LEFT) > 0) {
      //Prevent cursor underun
      if (cursor > 0) {
        ANXInputDrawCursor(row, col, startX, startY);
        cursor--;
      }

      if (cursor < messageLen) {
        cindex = ANXIndexOf(INPUT_CHARS, message[cursor]);
      } else {
        messageLen++;
        cindex = 0;
      }

      //Don't allow repeats
      clearButtonState();
    }

    if ((button & BUTTON_ENTER) > 0) {
      //Don't allow repeats
      clearButtonState();
      return;
    }
  }
}