Robofun 機器人論壇

 找回密碼
 申請會員
搜索
熱搜: 活動 交友 discuz
查看: 2528|回復: 1
打印 上一主題 下一主題

距離感測器和TM1637七段顯示器整合問題

[複製鏈接]
跳轉到指定樓層
1#
發表於 2018-4-24 15:22:22 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
目前想要做用距離感測器
然後把數據顯示在七段顯示器上面
一直卡在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         
}
2#
發表於 2018-4-24 16:31:26 | 只看該作者
#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 );


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};
void setup() {
  Serial.begin(9600); // Use Serial Monitor window
  pinMode(A0, INPUT); // Connect sensor to analog pin A0
  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
}
您需要登錄後才可以回帖 登錄 | 申請會員

本版積分規則

小黑屋|手機版|Archiver|機器人論壇 from 2005.07

GMT+8, 2024-4-24 19:04 , Processed in 0.140184 second(s), 6 queries , Apc On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表