SPEEDsSTACK stoppur (3 / 4 steg)
Steg 3: kod:
#include
#include
#include
#include
#include
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
#define röd 7
#define grön 8
#define ResetB 6
#define känsliga 20
#define delayRun 2000
#define blinkDelay 75
#if (SSD1306_LCDHEIGHT! = 64)
#error ("höjd felaktig, snälla fixa Adafruit_SSD1306.h!");
#endif
CapacitiveSensor cs_4_2 = CapacitiveSensor (5, 4); 10 M motstånd mellan stift 4 & 2, stift 2 är givarstaven, lägga till en tråd och eller folie om så önskas
CapacitiveSensor cs_4_6 = CapacitiveSensor (3, 2); 10 M motstånd mellan stift 4 & 6, stift 6 är givarstaven, lägga till en tråd och eller folie
booleska håll = false, runT = false;
långa holdTime, stoppur;
långa total1;
lång total2;
långa kalkylator, blinkCount = 0, över;
int timmar, minuter, sekunder, Tseconds;
void setup()
{
cs_4_2.set_CS_AutocaL_Millis(0xFFFFFFFF); stänga av autocalibrate på kanal 1 - bara som ett exempel
Serial.BEGIN(9600);
pinMode (röd, OUTPUT);
pinMode (gröna, OUTPUT);
display.BEGIN (SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0,0);
}
void loop()
{
*** Läs touch-sensorer
långa total1 = cs_4_2.capacitiveSensor(30);
lång total2 = cs_4_6.capacitiveSensor(30);
display.clearDisplay();
display.setCursor (0,0);
display.Print ("SPEEDsTACK");
display.display();
*** En touch bouth sidor
om (total1 > = känsliga & & total2 > = känsliga & & hålla == false) {
digitalWrite (grön, hög);
digitalWrite (röd, hög);
holdTime = millis() + delayRun;
Serial.Print ("holdTime =");
display.clearDisplay();
display.setCursor (0,0);
display.Print ("SPEEDsTACK");
display.setCursor(0,30);
display.Print ("--klar--");
display.display();
Håll = sant;
}
*** Gå grönt ljus efter fördröjning
om (millis() > = holdTime & & hålla == true) {
digitalWrite (grön, hög);
digitalWrite (röd, låg);
display.clearDisplay();
display.setCursor(10,30);
display.Print ("** gå **");
display.display();
medan (håll == true) {
Serial.println ("tag loop");
*** Väntar bouth orörd
medan (total1 > = känsliga & & total2 > = känsliga & & hålla == true) {
total1 = cs_4_2.capacitiveSensor(30);
total2 = cs_4_6.capacitiveSensor(30);
fördröjning (10).
}
total1 = cs_4_2.capacitiveSensor(30);
total2 = cs_4_6.capacitiveSensor(30);
*** Wating för nytt touch
medan (total1 < = känsliga || total2 < = känsliga & & hålla == true) {
om (runT == false) {
Serial.println ("*** nollställning ***");
Stoppur = millis() + 10.
runT = sant;
blinkCount = 0;
}
total1 = cs_4_2.capacitiveSensor(30);
total2 = cs_4_6.capacitiveSensor(30);
kalkylator = millis() - stoppur;
display.clearDisplay();
display.setCursor(0,0);
display.Print (kalkylator);
display.display();
Timmar = int(calculator / 3600000);
över = räknaren % 3600000;
Okej = int(over / 60000);
över = över % 60000;
Sekunder = int (över/1000);
Tseconds = % 1000;
display.clearDisplay();
display.setCursor (0,0);
display.Print ("SPEEDsTACK");
display.setCursor(0,30);
display.Print (timmar);
display.Print (":");
display.Print (okej);
display.Print (":");
display.Print (sekunder);
display.Print (":");
display.println (Tseconds);
display.display();
om (miniräknare > = blinkCount + blinkDelay) {
Serial.println ("*** BlinK ***");
digitalWrite (Green,! digitalRead (grön));
blinkCount = miniräknare;
}
}
om (runT == true) {
Stoppur = millis() - stoppur;
Timmar = int(stopWatch / 3600000);
över = stoppur % 3600000;
Okej = int(over / 60000);
över = över % 60000;
Sekunder = int (över/1000);
Tseconds = % 1000;
display.clearDisplay();
display.setCursor (0,0);
display.Print ("SPEEDsTACK");
display.setCursor(0,30);
display.Print (timmar);
display.Print (":");
display.Print (okej);
display.Print (":");
display.Print (sekunder);
display.Print (":");
display.println (Tseconds);
display.display();
Håll = false;
runT = false;
digitalWrite (gröna, låg);
blinkCount = millis();
medan (! digitalRead (ResetB)) {
om (millis() > = blinkCount + blinkDelay) {
Serial.println ("*** BlinK ***");
digitalWrite (Green,! digitalRead (grön));
digitalWrite (röd,! digitalRead (grön));
blinkCount = millis();
}
}
}
}
}
*** En touch endast en sida
om (total1 > = känsliga & & total2 < = känsliga || total1 < = känsliga & & total2 > = känsliga) {
digitalWrite (gröna, låg);
digitalWrite (röd, hög);
Håll = false;
display.clearDisplay();
display.setCursor (0,0);
display.Print ("SPEEDsTACK");
display.setCursor(32,30);
display.Print ("<<>> <>");
display.display();
Serial.Print (total1);
Serial.Print ("\t");
Serial.println (total1);
Serial.println ("ONE Touch");
}
Ingen beröring alls
om (total1 < = känsliga & & total2 < = känsliga) {
digitalWrite (gröna, låg);
digitalWrite (röd, låg);
display.clearDisplay();
display.setCursor (0,0);
display.Print ("SPEEDsTACK");
Håll = false;
Serial.println ("ingen Touch");
}
/*
Serial.Print(total1); sensor utdata 1
Serial.Print("\t");
Serial.println(total2); sensor utdata 2
*/
Delay(10); godtyckliga dröjsmål att begränsa data till seriell port
}