E:\Arduino\libraries\AdafruitGFX/Adafruit_GFX.h:28:7: note: candidate expects 1 argument, 2 provided
exit status 1
这种故障是为啥啊 想加个oled 有没有大佬帮忙改改程序!
- #include <Adafruit_SSD1306.h>
- #include <Wire.h>
- #include <Servo.h>.
- #include <Adafruit_GFX.h>
- #define OLED_RESET 4
- Adafruit_SSD1306 display(128, 64, &Wire, OLED_RESET);
- const int trigPin = 10;
- const int echoPin = 11;
- long duration;
- int distance;
- Servo myServo; //
- void setup() {
- display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
- display.setTextColor(WHITE);//开像素点发光
- display.clearDisplay();//清屏
- display.setTextSize(2); //设置字体大小
- pinMode(trigPin, OUTPUT);
- pinMode(echoPin, INPUT);
- Serial.begin(9600);
- myServo.attach(12); //
- }
- //
- void loop() {
- // 将伺服电机从 15 度旋转到 165 度
- for (int i = 15; i <= 165; i++) {
- myServo.write(i);
- delay(30);
- distance = calculateDistance();// Calls a function for calculating the distance measured by the Ultrasonic sensor for each degree
- Serial.print(i);
- Serial.print(",");
- Serial.print(distance);
- Serial.print("."); //
- }
- // 从 165 到 15 度重复前面的行
- for (int i = 165; i > 15; i--) {
- myServo.write(i);
- delay(30);
- distance = calculateDistance();
- Serial.print(i);
- Serial.print(",");
- Serial.print(distance);
- Serial.print(".");
- }
- display.clearDisplay();//清屏
- display.setCursor(50, 10);
- display.print(distance);
- display.println("cm");
- display.drawRect(0, 33, 128, 12, WHITE);
- display.fillRect(2, 35, map(distance, 2, 20, 2, 124), 8, WHITE);
- display.display();//开显示
- }
- // 计算超声波传感器测量距离的函数
- int calculateDistance() {
- digitalWrite(trigPin, LOW);
- delayMicroseconds(2);
- // Sets the trigPin on HIGH state for 10 micro seconds
- digitalWrite(trigPin, HIGH);
- delayMicroseconds(10);
- digitalWrite(trigPin, LOW);
- duration = pulseIn(echoPin, HIGH); // 读取 echoPin,以微秒为单位返回声波传播时间
- distance = duration * 0.034 / 2; //距离=持续时间*0.034/2;
- return distance;
- }
复制代码
|