[![231c955061c23ae1eb42af325e60c618.jpg](https://ppmm.org/images/2020/07/27/231c955061c23ae1eb42af325e60c618.jpg)](https://ppmm.org/image/NxGi)
[![e6f61db0770e25a24e8fdb96a523b092.jpg](https://ppmm.org/images/2020/07/27/e6f61db0770e25a24e8fdb96a523b092.jpg)](https://ppmm.org/image/N2Jc)
[![5b9455ae6f59b49f5c0f500ec4efd4d5.jpg](https://ppmm.org/images/2020/07/27/5b9455ae6f59b49f5c0f500ec4efd4d5.jpg)](https://ppmm.org/image/NN5R)
[![0a566afb39ad7e8aeed63f872086879b.jpg](https://ppmm.org/images/2020/07/27/0a566afb39ad7e8aeed63f872086879b.jpg)](https://ppmm.org/image/Nesp)
用霍尔传感器获取速度,然后显示在oled上。
随便用热熔胶糊上的,明天放车上试试再调整。
放个程序(基本上复制粘贴来的)
```
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_MOSI 9
#define OLED_CLK 10
#define OLED_DC 11
#define OLED_CS 12
#define OLED_RESET 13
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT,OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
unsigned long startTime = 0;
unsigned long endTime = 0;
float v = 0.0;
float vk = 0.0;
String vstr1 = "";
String vstr2 = "";
void setup() {
pinMode(2, INPUT);
attachInterrupt( digitalPinToInterrupt(2), onChange, CHANGE);
if (!display.begin(SSD1306_SWITCHCAPVCC)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;); // Don't proceed, loop forever
}
display.display();
delay(2000);
display.clearDisplay();
display.setTextSize(4);
display.setTextColor(SSD1306_WHITE);
display.setCursor(8, 16);
display.println(F("READY"));
display.display();
}
void loop() {
delay(500);
}
void update(String text,int x = 0,int y = 16,int fontSize = 2) {
display.setTextSize(fontSize);
display.setTextColor(SSD1306_WHITE);
display.setCursor(x, y);
display.println(text);
display.display();
}
void onChange() {
if (digitalRead(2) == HIGH) {
startTime = millis();
vstr1 = "";
vstr2 = "";
}
else {
endTime = millis();
v = 2140.0 / (endTime - startTime);
vk = v * 3.60;
vstr1 += String(v);
vstr1 += "m/s ";
vstr2 += String(vk);
vstr2 += "km/h";
display.clearDisplay();
display.fillRect(0,49,v*128.0/10.0,63, SSD1306_WHITE);
update(F("Cycling..."),0,0);
update(vstr1);
update(vstr2,0,32);
}
}
```