State machine

Dependencies:   mbed Adafruit_GFX BioroboticsMotorControl MODSERIAL BioroboticsEMGFilter

Committer:
brass_phoenix
Date:
Tue Oct 30 11:40:00 2018 +0000
Revision:
3:4b19b6cf6cc7
Child:
4:5a44ab7e94b3
+ Added screen basics.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
brass_phoenix 3:4b19b6cf6cc7 1 #pragma once
brass_phoenix 3:4b19b6cf6cc7 2
brass_phoenix 3:4b19b6cf6cc7 3 #include "mbed.h"
brass_phoenix 3:4b19b6cf6cc7 4
brass_phoenix 3:4b19b6cf6cc7 5 // Uncomment this in the adafruit config.h to turn off the builtin splash
brass_phoenix 3:4b19b6cf6cc7 6 //#define NO_SPLASH_ADAFRUIT
brass_phoenix 3:4b19b6cf6cc7 7 // Uncomment this in the adafruit config.h to enable all functionality
brass_phoenix 3:4b19b6cf6cc7 8 //#define GFX_WANT_ABSTRACTS
brass_phoenix 3:4b19b6cf6cc7 9
brass_phoenix 3:4b19b6cf6cc7 10 #include "Adafruit_SSD1306.h"
brass_phoenix 3:4b19b6cf6cc7 11
brass_phoenix 3:4b19b6cf6cc7 12
brass_phoenix 3:4b19b6cf6cc7 13 class Screen
brass_phoenix 3:4b19b6cf6cc7 14 {
brass_phoenix 3:4b19b6cf6cc7 15 private:
brass_phoenix 3:4b19b6cf6cc7 16 I2C i2c;
brass_phoenix 3:4b19b6cf6cc7 17 Adafruit_SSD1306_I2c oled;
brass_phoenix 3:4b19b6cf6cc7 18 public:
brass_phoenix 3:4b19b6cf6cc7 19 // The screen we use doesn't have a reset pin, but it needs one anyway.
brass_phoenix 3:4b19b6cf6cc7 20 // Use a pin we don't use.
brass_phoenix 3:4b19b6cf6cc7 21 Screen(PinName sda, PinName scl, PinName reset):
brass_phoenix 3:4b19b6cf6cc7 22 i2c(sda, scl),
brass_phoenix 3:4b19b6cf6cc7 23 oled(i2c, reset) {
brass_phoenix 3:4b19b6cf6cc7 24
brass_phoenix 3:4b19b6cf6cc7 25 // according to the spec the max bitrate for the SSD1308 is 400 kbit/s
brass_phoenix 3:4b19b6cf6cc7 26 i2c.frequency(400000);
brass_phoenix 3:4b19b6cf6cc7 27
brass_phoenix 3:4b19b6cf6cc7 28 // IMPORTANT! Otherwise nothing will be displayed.
brass_phoenix 3:4b19b6cf6cc7 29 oled.clearDisplay();
brass_phoenix 3:4b19b6cf6cc7 30 display();
brass_phoenix 3:4b19b6cf6cc7 31 }
brass_phoenix 3:4b19b6cf6cc7 32
brass_phoenix 3:4b19b6cf6cc7 33 void display() {
brass_phoenix 3:4b19b6cf6cc7 34 // Apparently the display only updates every 2 "display" calls.
brass_phoenix 3:4b19b6cf6cc7 35 // This is a bug in the library.
brass_phoenix 3:4b19b6cf6cc7 36 oled.display();
brass_phoenix 3:4b19b6cf6cc7 37 oled.display();
brass_phoenix 3:4b19b6cf6cc7 38 }
brass_phoenix 3:4b19b6cf6cc7 39
brass_phoenix 3:4b19b6cf6cc7 40 // Returns a direct handle to the screen.
brass_phoenix 3:4b19b6cf6cc7 41 // Be carefull while using the handle.
brass_phoenix 3:4b19b6cf6cc7 42 Adafruit_SSD1306_I2c get_screen_handle() {
brass_phoenix 3:4b19b6cf6cc7 43 return oled;
brass_phoenix 3:4b19b6cf6cc7 44 }
brass_phoenix 3:4b19b6cf6cc7 45
brass_phoenix 3:4b19b6cf6cc7 46 };