| 
 | 
 
目前想要做用距離感測器 
然後把數據顯示在七段顯示器上面 
一直卡在Arduino開發板編譯錯誤 
希望各位大大幫忙看是哪裡寫錯 
 
(設這是原始檔) 
#include <Arduino.h> 
#include <TM1637Display.h> 
 
#define CLK 2 // connect CLK to pin 2 
#define DIO 3 // connect DIO to pin 3 
#define TEST_DELAY 100 
 uint8_t blank[] = { 0x0, 0x0, 0x0, 0x0 }; 
TM1637Display display( CLK, DIO ); 
 
void setup() { 
Serial.begin(9600); // Use Serial Monitor window 
pinMode(A0,INPUT); // Connect sensor to analog pin A0 
int sensorValue; 
int distance; 
int number; 
int count = 0; 
unsigned long time=0; 
const byte num[10]= 
{ B11000000,B11111001,B10100100,B10110000,B10011001, 
B10010010,B10000010,B11111000,B10000000,B10010000}; 
const int seg[]={2,3,4,5,6,7,8,9}; 
const int digit[]={10,11,12,13}; 
display.setBrightness(0x0f); 
} 
void loop() { 
   
 sensorValue = analogRead(0);    
 if(sensorValue>=280&&sensorValue<=620) // If sensorValue between 280 ~ 620 ,will be touch off 
 {  
   distance = 28250 / ( sensorValue - 229.5 ); 
   long int averaging = 0; 
   //儲存10次距離數據 
   for(int i = 0 ; i<2 ; i++ ) //sampimg 10 time within 1 seconds 
   { 
    averaging = averaging + distance; 
    delay(100); 
   } 
   //得到距離數據之平均值 
   distance = averaging / 2;  
  Serial.print("Distance: "); 
  display.setSegments(blank); 
  int dis = distance(); 
  display.showNumberDec(dis , false , 3 , 1); 
  Serial.print(distance); 
  Serial.println("cm"); 
 
   averaging = 0; 
  //重置紅外線感測器之數值為0 
  delay(1500); 
  //Wait another 1.5 second for the next read 
  //延遲1.5秒 
 } 
  delay(500);  //Wait another 1/2 second for the next read          
} |   
 
 
 
 |