Bradley Kohler
/
Nucleo_Ultrasonic
Small example using ultrasonic
main.cpp@2:00f96140b44b, 2017-11-22 (annotated)
- Committer:
- kohlerba
- Date:
- Wed Nov 22 21:38:42 2017 +0000
- Revision:
- 2:00f96140b44b
- Parent:
- 1:8fafe8a483e9
Removed libraries
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kohlerba | 0:bd7dd6e79e36 | 1 | #include "mbed.h" |
kohlerba | 0:bd7dd6e79e36 | 2 | #include "Adafruit_SSD1306.h" |
kohlerba | 0:bd7dd6e79e36 | 3 | |
kohlerba | 0:bd7dd6e79e36 | 4 | #define SSD1306_ADDRESS 0x78 |
kohlerba | 0:bd7dd6e79e36 | 5 | |
kohlerba | 0:bd7dd6e79e36 | 6 | // an I2C sub-class that provides a constructed default |
kohlerba | 0:bd7dd6e79e36 | 7 | class I2CPreInit : public I2C |
kohlerba | 0:bd7dd6e79e36 | 8 | { |
kohlerba | 0:bd7dd6e79e36 | 9 | public: |
kohlerba | 0:bd7dd6e79e36 | 10 | I2CPreInit(PinName sda, PinName scl) : I2C(sda, scl) |
kohlerba | 0:bd7dd6e79e36 | 11 | { |
kohlerba | 0:bd7dd6e79e36 | 12 | frequency(400000); |
kohlerba | 0:bd7dd6e79e36 | 13 | start(); |
kohlerba | 0:bd7dd6e79e36 | 14 | }; |
kohlerba | 0:bd7dd6e79e36 | 15 | }; |
kohlerba | 0:bd7dd6e79e36 | 16 | |
kohlerba | 0:bd7dd6e79e36 | 17 | uint8_t led_height = 64; |
kohlerba | 0:bd7dd6e79e36 | 18 | uint8_t led_width = 128; |
kohlerba | 0:bd7dd6e79e36 | 19 | |
kohlerba | 1:8fafe8a483e9 | 20 | I2CPreInit gI2C(D14,D15); |
kohlerba | 0:bd7dd6e79e36 | 21 | Adafruit_SSD1306_I2c gOled(gI2C,PA_8,SSD1306_ADDRESS,led_height,led_width); |
kohlerba | 0:bd7dd6e79e36 | 22 | |
kohlerba | 0:bd7dd6e79e36 | 23 | DigitalOut led(LED1); |
kohlerba | 0:bd7dd6e79e36 | 24 | |
kohlerba | 0:bd7dd6e79e36 | 25 | int main() { |
kohlerba | 0:bd7dd6e79e36 | 26 | gOled.begin(); |
kohlerba | 0:bd7dd6e79e36 | 27 | gOled.clearDisplay(); |
kohlerba | 0:bd7dd6e79e36 | 28 | gOled.display(); |
kohlerba | 0:bd7dd6e79e36 | 29 | wait(0.1); |
kohlerba | 0:bd7dd6e79e36 | 30 | while(1){ |
kohlerba | 0:bd7dd6e79e36 | 31 | led = !led; |
kohlerba | 0:bd7dd6e79e36 | 32 | gOled.clearDisplay(); |
kohlerba | 0:bd7dd6e79e36 | 33 | gOled.drawPixel(0,0,WHITE); |
kohlerba | 1:8fafe8a483e9 | 34 | gOled.fillCircle(63, 0, 10, WHITE); |
kohlerba | 1:8fafe8a483e9 | 35 | gOled.display(); |
kohlerba | 1:8fafe8a483e9 | 36 | wait(1); |
kohlerba | 1:8fafe8a483e9 | 37 | gOled.clearDisplay(); |
kohlerba | 1:8fafe8a483e9 | 38 | gOled.fillCircle(63, 31, 20, WHITE); |
kohlerba | 0:bd7dd6e79e36 | 39 | gOled.display(); |
kohlerba | 1:8fafe8a483e9 | 40 | wait(1); |
kohlerba | 1:8fafe8a483e9 | 41 | gOled.clearDisplay(); |
kohlerba | 1:8fafe8a483e9 | 42 | gOled.fillCircle(63, 63, 30, WHITE); |
kohlerba | 1:8fafe8a483e9 | 43 | gOled.display(); |
kohlerba | 1:8fafe8a483e9 | 44 | wait(1); |
kohlerba | 0:bd7dd6e79e36 | 45 | } |
kohlerba | 0:bd7dd6e79e36 | 46 | } |