commit
dc36f1906c
@ -0,0 +1,27 @@ |
||||
This source code is released under the DWTW license. |
||||
|
||||
This program is free software; you can redistribute it and/or modify it under the terms of the Do What Thou Wilt License. |
||||
|
||||
Boundless Public License |
||||
DO WHAT THOU WILT |
||||
TO PUBLIC LICENSE |
||||
|
||||
Version 2.55 |
||||
|
||||
Everyone is permitted to copy and distribute verbatim or modified copies of this license document, and changing it in full or in part is allowed without any restrictions. |
||||
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION |
||||
|
||||
0. Do what thou wilt shall be the whole of the Law. |
||||
|
||||
DWTWL – a license with a single requirement: DO WHAT THOU WILT |
||||
|
||||
The license provides more freedom than any other one (such as GPL or BSD) and does not require saving the license text on copying. |
||||
|
||||
DWTWL – an accomplished and eligible license for free text, code and any other symbols (including the software, documentation and artwork). |
||||
|
||||
The license does not contain a "no warranty" clause. DWTWL can be used in countries that do not legally acknowledge the transition to public domain. |
||||
|
||||
Summary: |
||||
|
||||
An author-creator gives their source code to the world for free, without becoming distracted by worldly thinking regarding how and why the others will use it. |
@ -0,0 +1,3 @@ |
||||
# display sensor button |
||||
|
||||
 |
Binary file not shown.
@ -0,0 +1,124 @@ |
||||
#include <Arduino.h> |
||||
#include <Thread.h> |
||||
#include <SevenSegmentExtended.h> // DisplayLib // Extended TM1637 library https://github.com/bremme/arduino-tm1637 |
||||
#include "DHT.h" // DHTlib |
||||
#define DHTPIN 5 // DHTsensorSetting // DHT pin
|
||||
#define DHTTYPE DHT22 // DHTsensorSetting // DHT11 / DHT21 / DHT22
|
||||
DHT dht(DHTPIN, DHTTYPE); // DHTsensorSetting
|
||||
const byte PIN_CLK = 2; // DisplaySetting // CLK pin
|
||||
const byte PIN_DIO = 3; // DisplaySetting // DIO pin
|
||||
bool displayOn = false; // DisplaySetting // Boolian for store display power status
|
||||
SevenSegmentExtended display(PIN_CLK, PIN_DIO); // DisplaySetting
|
||||
const byte buttonPin = 4; // ButtonSetting // Button pin (a 10K resistor is necessary)
|
||||
long buttonPressed = 0; // ButtonSetting // Button ms pressed counter
|
||||
long previousButtonMillis = 0; // ButtonSetting // Button previous press counter
|
||||
byte buttonView = 0; // ButtonSetting // Button viewing state
|
||||
int buttonInterval = 10000; // ButtonSetting // Interval for highlighting 4-Digit Display after pressing button
|
||||
int buttonLongPress = 2500; // ButtonSetting // Interval for long press button action
|
||||
int buttonCheck = 200; // ButtonSetting // Interval for checking button state
|
||||
|
||||
// Threads:
|
||||
Thread pressButtonThread = Thread(); // Create thread for button state checking
|
||||
|
||||
void setup() { |
||||
Serial.begin(9600); // Initializes the Serial connection @ 9600 baud for debug
|
||||
dht.begin(); // DHTsensorSetting // Initializes the sensor
|
||||
display.begin(); // DisplaySetting // Initializes the display
|
||||
displayOn = true; // Display On
|
||||
display.setBacklight(100); // Display On - set the brightness to 100 %
|
||||
display.print("INIT-TINI"); // Display initialization
|
||||
pinMode(buttonPin, INPUT); // ButtonSetting
|
||||
// Button state cheking thread:
|
||||
pressButtonThread.onRun(pressButton); |
||||
pressButtonThread.setInterval(buttonCheck); |
||||
display.off(); // Display Off
|
||||
displayOn = false; // Display Off
|
||||
} |
||||
|
||||
void loop() { |
||||
// Threads init:
|
||||
if (pressButtonThread.shouldRun()) |
||||
pressButtonThread.run(); |
||||
// Serial interaction:
|
||||
if (Serial.available() > 0) { |
||||
int incomingByte = Serial.read() - 48; |
||||
if (incomingByte == 5) { |
||||
float humFloat; |
||||
readDHThum(&humFloat); |
||||
Serial.println(humFloat); |
||||
} |
||||
if (incomingByte == 6) { |
||||
float tempFloat; |
||||
readDHTtemp(&tempFloat); |
||||
Serial.println(tempFloat); |
||||
} |
||||
} |
||||
} |
||||
|
||||
// Check button pressing thread
|
||||
void pressButton() { |
||||
// Display off after buttonInterval ms slack
|
||||
unsigned long currentMillis = millis(); |
||||
if (currentMillis - previousButtonMillis > buttonInterval) { |
||||
previousButtonMillis = currentMillis; |
||||
if (displayOn == true) { |
||||
display.off(); |
||||
displayOn = false; |
||||
} |
||||
} |
||||
|
||||
if (digitalRead(buttonPin) == HIGH) { |
||||
buttonPressed = buttonPressed + 200; |
||||
if (buttonPressed > buttonLongPress) { |
||||
buttonPressed = 0; |
||||
longPress(); |
||||
} |
||||
previousButtonMillis = currentMillis; |
||||
display.on(); |
||||
displayOn = true; |
||||
if (buttonView == 0) { |
||||
float tempFloat; |
||||
readDHTtemp(&tempFloat); |
||||
int tempInt = (int)tempFloat; |
||||
if (tempInt < 0) |
||||
tempInt = tempInt * (-1); |
||||
byte rawData[4]; |
||||
rawData[0] = display.encode(tempInt / 10); |
||||
rawData[1] = display.encode(tempInt % 10); |
||||
rawData[2] = B01100011; // degree
|
||||
rawData[3] = display.encode('c'); |
||||
display.printRaw(rawData); |
||||
} else if (buttonView == 1) { |
||||
float humFloat; |
||||
readDHThum(&humFloat); |
||||
int humInt = (int)humFloat; |
||||
byte rawData[4]; |
||||
rawData[0] = display.encode('h'); |
||||
rawData[1] = display.encode('u'); |
||||
rawData[2] = display.encode(humInt / 10); |
||||
rawData[3] = display.encode(humInt % 10); |
||||
display.printRaw(rawData); |
||||
} |
||||
if (buttonView < 1) buttonView += 1; |
||||
else buttonView = 0; |
||||
} else { |
||||
buttonPressed = 0; |
||||
} |
||||
} |
||||
|
||||
|
||||
// DHT Temperature
|
||||
void readDHTtemp(float *a) { |
||||
float t = dht.readTemperature(); |
||||
*a = t; |
||||
} |
||||
|
||||
// DHT Humidity
|
||||
void readDHThum(float *a) { |
||||
float h = dht.readHumidity(); |
||||
*a = h; |
||||
} |
||||
|
||||
void longPress() { |
||||
display.print("-doctor-equivalent-me-"); |
||||
} |
After Width: | Height: | Size: 64 KiB |
@ -0,0 +1,4 @@ |
||||
#!/bin/sh |
||||
echo "5" > /dev/ttyUSB0 |
||||
HUM=`dd if=/dev/ttyUSB0 count=1` |
||||
echo $HUM |
@ -0,0 +1,4 @@ |
||||
#!/bin/sh |
||||
echo "6" > /dev/ttyUSB0 |
||||
TEMP=`dd if=/dev/ttyUSB0 count=1` |
||||
echo $TEMP |
Loading…
Reference in new issue