Bradley Kohler
/
Nucleo_Ultrasonic
Small example using ultrasonic
main.cpp@0:bd7dd6e79e36, 2017-08-11 (annotated)
- Committer:
- kohlerba
- Date:
- Fri Aug 11 17:36:11 2017 +0000
- Revision:
- 0:bd7dd6e79e36
- Child:
- 1:8fafe8a483e9
Starting of Ultrasonic sensor for Nucleo
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 | // OLED: SDA -> Arduino Analog 4 |
kohlerba | 0:bd7dd6e79e36 | 5 | // SCL -> Arduino Analog 5 |
kohlerba | 0:bd7dd6e79e36 | 6 | |
kohlerba | 0:bd7dd6e79e36 | 7 | #define SSD1306_ADDRESS 0x78 |
kohlerba | 0:bd7dd6e79e36 | 8 | |
kohlerba | 0:bd7dd6e79e36 | 9 | // an I2C sub-class that provides a constructed default |
kohlerba | 0:bd7dd6e79e36 | 10 | class I2CPreInit : public I2C |
kohlerba | 0:bd7dd6e79e36 | 11 | { |
kohlerba | 0:bd7dd6e79e36 | 12 | public: |
kohlerba | 0:bd7dd6e79e36 | 13 | I2CPreInit(PinName sda, PinName scl) : I2C(sda, scl) |
kohlerba | 0:bd7dd6e79e36 | 14 | { |
kohlerba | 0:bd7dd6e79e36 | 15 | frequency(400000); |
kohlerba | 0:bd7dd6e79e36 | 16 | start(); |
kohlerba | 0:bd7dd6e79e36 | 17 | }; |
kohlerba | 0:bd7dd6e79e36 | 18 | }; |
kohlerba | 0:bd7dd6e79e36 | 19 | |
kohlerba | 0:bd7dd6e79e36 | 20 | uint8_t led_height = 64; |
kohlerba | 0:bd7dd6e79e36 | 21 | uint8_t led_width = 128; |
kohlerba | 0:bd7dd6e79e36 | 22 | |
kohlerba | 0:bd7dd6e79e36 | 23 | I2CPreInit gI2C(PC_1,PC_0); |
kohlerba | 0:bd7dd6e79e36 | 24 | Adafruit_SSD1306_I2c gOled(gI2C,PA_8,SSD1306_ADDRESS,led_height,led_width); |
kohlerba | 0:bd7dd6e79e36 | 25 | |
kohlerba | 0:bd7dd6e79e36 | 26 | DigitalOut led(LED1); |
kohlerba | 0:bd7dd6e79e36 | 27 | |
kohlerba | 0:bd7dd6e79e36 | 28 | int main() { |
kohlerba | 0:bd7dd6e79e36 | 29 | gOled.begin(); |
kohlerba | 0:bd7dd6e79e36 | 30 | gOled.clearDisplay(); |
kohlerba | 0:bd7dd6e79e36 | 31 | gOled.display(); |
kohlerba | 0:bd7dd6e79e36 | 32 | wait(0.1); |
kohlerba | 0:bd7dd6e79e36 | 33 | while(1){ |
kohlerba | 0:bd7dd6e79e36 | 34 | led = !led; |
kohlerba | 0:bd7dd6e79e36 | 35 | gOled.clearDisplay(); |
kohlerba | 0:bd7dd6e79e36 | 36 | gOled.drawPixel(0,0,WHITE); |
kohlerba | 0:bd7dd6e79e36 | 37 | gOled.fillCircle(64, 42, 10, WHITE); |
kohlerba | 0:bd7dd6e79e36 | 38 | gOled.display(); |
kohlerba | 0:bd7dd6e79e36 | 39 | wait(0.1); |
kohlerba | 0:bd7dd6e79e36 | 40 | } |
kohlerba | 0:bd7dd6e79e36 | 41 | } |