Stap 5: Me-Nixie-buis weergeven.
* Bestandsnaam: Snelheid Detector.
* Auteur: Yuwei
* Bijgewerkt: Yuwei
* Datum: 3/13/2014
* Beschrijving: Ik ben met behulp van een Makeblock Me-LightSensor te maken van een wiel snelheid detector.
U kunt deze Me-LightSensor verbinden met de PORT_3, PORT_6, PORT_7, PORT_8 van Me-plint.
* Copyright (C) 2013 Maker werkt Technology Co., Ltd. Alle rechten voorbehouden.
* http://www.makeblock.cc/
**************************************************************************/
#include < Makeblock.h >
#include < Arduino.h >
#include < SoftwareSerial.h >
#include < EEPROM.h >
#include < Wire.h >
#include < TimerOne.h >
#include < avr/pgmspace.h >
#include "TM1637.h"
#define op 1
#define uit 0
[int8_t TimeDisp] = {0x00, 0x00, 0x00, 0x00};
unsigned char ClockPoint = 1;
unsigned char Update;
unsigned char microsecond_10 = 0;
unsigned char tweede;
unsigned char _microsecond_10 = 0;
unsigned char _second;
unsigned int eepromaddr;
Booleaanse Flag_ReadTime;
#define CLK A3 / / pins definities voor TM1637 en kan worden gewijzigd in andere poorten
#define DIO A2 //Digital tude is aangesloten op poort 7.
TM1637 tm1637(CLK,DIO);
MeLightSensor lightSensor(PORT_6);
MeDCMotor motor1(M1);
uint8_t motorSpeed = 100;
int waarde = 0; een variabele voor de lightSensor de waarde
int count = 0;
int buff [3];
int som = 0;
int omega;
statische int matrix [3] = {-1,4, -1};
VOID Setup
{
seriële communicatie 9600 bps initialiseren
Serial.begin(9600);
tm1637.set (5); //BRIGHT_TYPICAL = 2, BRIGHT_DARKEST = 0, HELDERSTE = 7;
tm1637.init();
Timer1.initialize (10000); //timing voor 10ms
Timer1.attachInterrupt (TimingISR), //Declareer de interrupt serve routine: TimingISR
lightSensor.lightOn();
}
lange time0 = 0;
void loop
{
waarde = lightSensor.read();
motor1.run(motorSpeed);
Lees de lightSensor waarde:
Buff [0] = buff [1];
Buff [1] = buff [2];
Buff [2] = waarde;
som = matrix [0] * buff [0] + matrix [1] * buff [1] + matrix [2] * buff [2];
Serial.println(Sum); uncomment deze lijn en commentaar van de volgende 15 lijnen als u wilt zien van de gegevens in seriële grafieken
if(Sum >750)
{
Graaf ++;
lange t=millis();
lange deltaT = t-time0;
if(deltaT>100)
{
Omega = 360000/deltaT;
Printf fuction kunt u gebruiken als u de bibliotheek "printf" aan afdrukken klasse toevoegen.
meer informatie over http://playground.arduino.cc/Main/Printf#.UyE3NxSSz9F
if(update == on)
{
TimeUpdate(omega);
tm1637.display(TimeDisp);
}
Serial.Print(Omega);
Serial.println("rad/s");
}
time0 = t;
}
delay(2);
}
//************************************************
VOID TimingISR()
{
microsecond_10 ++;
Update = ON;
if(microsecond_10 == 100) {}
tweede ++;
if(Second == 60)
{
tweede = 0;
}
microsecond_10 = 0;
}
ClockPoint = (~ ClockPoint) & 0x01;
if(Flag_ReadTime == 0)
{
_microsecond_10 = microsecond_10;
_second = tweede;
}
}
VOID TimeUpdate(int value)
{
Als (ClockPoint) tm1637.point (POINT_ON); //POINT_ON = 1, POINT_OFF = 0;
anders tm1637.point(POINT_ON);
TimeDisp [0] = waarde/1000;
TimeDisp [1] = waarde/100;
TimeDisp [2] = waarde/10 - TimeDisp [1] * 10;
TimeDisp [3] = waarde % 10;
Update = OFF;
}
Dat is alles. Start bouw uw eigen. Hebt u mening over, kunt u gewoon post-it hier of bezoek ons forum met ons te bespreken.