Code Blink Project


SUBMITTED BY: aarock1234

DATE: May 2, 2019, 6:03 p.m.

FORMAT: C++

SIZE: 2.0 kB

HITS: 446

  1. #include <SPI.h>
  2. #include <Wire.h>
  3. #include <Adafruit_GFX.h>
  4. #include <Adafruit_SSD1306.h>
  5. #define OLED_RESET 4
  6. #define MenuButton 2
  7. Adafruit_SSD1306 display(OLED_RESET);
  8. int blinkcount=0;
  9. int blinkinterval = 500;
  10. int blinkinterval2 = 300;
  11. unsigned long blinkTimer = 0;
  12. int displaystate=1;
  13. float Messwert;
  14. int z = 0;
  15. void EINHEIT() //muss nun hier stehen, weil sonst nicht vom setup() aus aufrufbar
  16. {
  17. display.setTextSize(1.5);
  18. display.setCursor(108, 23);
  19. display.println("bar");
  20. }
  21. void setup()
  22. {
  23. Serial.begin(9600);
  24. display.begin(SSD1306_SWITCHCAPVCC);
  25. display.clearDisplay();
  26. display.setTextColor(WHITE);
  27. EINHEIT(); //ein mal reicht immer noch
  28. display.setTextSize(3.5); //Nun reicht das auch ein mal
  29. }
  30. void loop()
  31. {
  32. if (millis() >= blinkTimer && blinkcount <= 6)
  33. { blinkcount++;
  34. switch (displaystate)
  35. {
  36. case 1:
  37. blinkTimer=millis()+blinkinterval; //erste Zeitvorgabe nutzen
  38. display.setCursor(23, 9);
  39. display.setTextColor(WHITE);
  40. display.println(Messwert);
  41. display.display();
  42. displaystate=2; //einstellen, dass das case 2 als nächstes verarbeitet wird
  43. break; //gesamten switch verlassen
  44. case 2:
  45. blinkTimer=millis()+blinkinterval2; //zweite Zeitvorgabe nutzen
  46. display.setCursor(23, 9);
  47. display.setTextColor(BLACK);
  48. display.println(Messwert); //Mit Hintergrundfarbe das gleiche erneut schreiben, um es zu löschen. Ist besser so. Für die Zunkunft nützlich.
  49. display.display();
  50. displaystate=1; //einstellen, dass nun wieder case 1 als nächstes verarbeitet wird
  51. break;
  52. default: //wird ausgeführt, wenn weder 1 noch 2 in displaystate steht, also kein case passt. Sollte hier nie ausgeführt werden.
  53. display.setCursor(23, 9);
  54. display.setTextColor(WHITE);
  55. display.println("ERR");
  56. }
  57. }
  58. }

comments powered by Disqus