commit
b6f8617a8c
@ -0,0 +1,2 @@ |
||||
.pio |
||||
.vscode |
@ -0,0 +1,67 @@ |
||||
# Continuous Integration (CI) is the practice, in software |
||||
# engineering, of merging all developer working copies with a shared mainline |
||||
# several times a day < https://docs.platformio.org/page/ci/index.html > |
||||
# |
||||
# Documentation: |
||||
# |
||||
# * Travis CI Embedded Builds with PlatformIO |
||||
# < https://docs.travis-ci.com/user/integration/platformio/ > |
||||
# |
||||
# * PlatformIO integration with Travis CI |
||||
# < https://docs.platformio.org/page/ci/travis.html > |
||||
# |
||||
# * User Guide for `platformio ci` command |
||||
# < https://docs.platformio.org/page/userguide/cmd_ci.html > |
||||
# |
||||
# |
||||
# Please choose one of the following templates (proposed below) and uncomment |
||||
# it (remove "# " before each line) or use own configuration according to the |
||||
# Travis CI documentation (see above). |
||||
# |
||||
|
||||
|
||||
# |
||||
# Template #1: General project. Test it using existing `platformio.ini`. |
||||
# |
||||
|
||||
# language: python |
||||
# python: |
||||
# - "2.7" |
||||
# |
||||
# sudo: false |
||||
# cache: |
||||
# directories: |
||||
# - "~/.platformio" |
||||
# |
||||
# install: |
||||
# - pip install -U platformio |
||||
# - platformio update |
||||
# |
||||
# script: |
||||
# - platformio run |
||||
|
||||
|
||||
# |
||||
# Template #2: The project is intended to be used as a library with examples. |
||||
# |
||||
|
||||
# language: python |
||||
# python: |
||||
# - "2.7" |
||||
# |
||||
# sudo: false |
||||
# cache: |
||||
# directories: |
||||
# - "~/.platformio" |
||||
# |
||||
# env: |
||||
# - PLATFORMIO_CI_SRC=path/to/test/file.c |
||||
# - PLATFORMIO_CI_SRC=examples/file.ino |
||||
# - PLATFORMIO_CI_SRC=path/to/test/directory |
||||
# |
||||
# install: |
||||
# - pip install -U platformio |
||||
# - platformio update |
||||
# |
||||
# script: |
||||
# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N |
@ -0,0 +1,32 @@ |
||||
; PlatformIO Project Configuration File |
||||
; |
||||
; Build options: build flags, source filter |
||||
; Upload options: custom upload port, speed and extra flags |
||||
; Library options: dependencies, extra library storages |
||||
; Advanced options: extra scripting |
||||
; |
||||
; Please visit documentation for the other options and examples |
||||
; https://docs.platformio.org/page/projectconf.html |
||||
|
||||
[platformio] |
||||
default_envs = leonardo |
||||
|
||||
[env] |
||||
framework = arduino |
||||
|
||||
[env:nodemcuv2] |
||||
platform = espressif8266 |
||||
board = nodemcuv2 |
||||
build_flags = |
||||
-D DIALING_PIN=D5 |
||||
-D PULSE_PIN=D6 |
||||
|
||||
[env:leonardo] |
||||
platform = atmelavr |
||||
board = leonardo |
||||
lib_deps = |
||||
Keyboard |
||||
build_flags = |
||||
-D FEATURE_KEYBOARD |
||||
-D DIALING_PIN=13 |
||||
-D PULSE_PIN=12 |
@ -0,0 +1,118 @@ |
||||
#include <Arduino.h> |
||||
#ifdef FEATURE_KEYBOARD |
||||
#include <Keyboard.h> |
||||
#endif |
||||
|
||||
int dialingPin = DIALING_PIN; |
||||
int pulsePin = PULSE_PIN; |
||||
|
||||
void setup() { |
||||
Serial.begin(9600); |
||||
#ifdef FEATURE_KEYBOARD |
||||
Keyboard.begin(); |
||||
#endif |
||||
pinMode(dialingPin, INPUT_PULLUP); |
||||
pinMode(pulsePin, INPUT_PULLUP); |
||||
Serial.println("Start Wählscheibe"); |
||||
} |
||||
|
||||
bool dialing = false; |
||||
bool pulse = false; |
||||
|
||||
bool dialingLast = false; |
||||
bool pulseLast = false; |
||||
|
||||
bool dialingVal = false; |
||||
bool pulseVal = false; |
||||
|
||||
bool dialingValLast = false; |
||||
bool pulseValLast = false; |
||||
|
||||
unsigned long dialingTimeOn = 0; |
||||
unsigned long dialingTimeOff = 0; |
||||
unsigned long pulseTimeOn = 0; |
||||
unsigned long pulseTimeOff = 0; |
||||
|
||||
int count = 0; |
||||
|
||||
void loop() { |
||||
dialingVal = digitalRead(dialingPin) == LOW; |
||||
pulseVal = digitalRead(pulsePin) == HIGH; |
||||
|
||||
// DIALING
|
||||
// Schalter geschlossen UND vorher offen
|
||||
if (dialingVal && !dialingValLast) { |
||||
dialingTimeOn = micros(); |
||||
} |
||||
|
||||
// Schalter offen UND seit mindestens einer Weile
|
||||
if (dialingVal && ((micros() - dialingTimeOn) > 3000)) { |
||||
dialing = true; |
||||
} |
||||
|
||||
// Schalter offen UND vorher geschlossen
|
||||
if (!dialingVal && dialingValLast) { |
||||
dialingTimeOff = micros(); |
||||
} |
||||
|
||||
// Schalter offen UND seit mindestens einer Weile
|
||||
if (!dialingVal && ((micros() - dialingTimeOff) > 3000)) { |
||||
dialing = false; |
||||
} |
||||
|
||||
// PULSE
|
||||
// Schalter geschlossen UND vorher offen
|
||||
if (pulseVal && !pulseValLast) { |
||||
pulseTimeOn = micros(); |
||||
} |
||||
|
||||
// Schalter offen UND seit mindestens einer Weile
|
||||
if (pulseVal && ((micros() - pulseTimeOn) > 3000)) { |
||||
pulse = true; |
||||
} |
||||
|
||||
// Schalter offen UND vorher geschlossen
|
||||
if (!pulseVal && pulseValLast) { |
||||
pulseTimeOff = micros(); |
||||
} |
||||
|
||||
// Schalter offen UND seit mindestens einer Weile
|
||||
if (!pulseVal && ((micros() - pulseTimeOff) > 3000)) { |
||||
pulse = false; |
||||
} |
||||
|
||||
// INTERPRET
|
||||
if (dialing && !dialingLast) { |
||||
#ifdef DEBUG |
||||
Serial.println("Start dialing"); |
||||
#endif |
||||
count = 0; |
||||
} |
||||
|
||||
if (dialing) { |
||||
if (pulse && !pulseLast) { |
||||
#ifdef DEBUG |
||||
Serial.print("+"); |
||||
#endif |
||||
count++; |
||||
} |
||||
} |
||||
|
||||
if (!dialing && dialingLast) { |
||||
#ifdef DEBUG |
||||
Serial.println(""); |
||||
Serial.println("Stop dialing"); |
||||
#endif |
||||
unsigned int output = count % 10; |
||||
Serial.println(output); |
||||
#ifdef FEATURE_KEYBOARD |
||||
Keyboard.print(output); |
||||
#endif |
||||
} |
||||
|
||||
dialingLast = dialing; |
||||
pulseLast = pulse; |
||||
|
||||
dialingValLast = dialingVal; |
||||
pulseValLast = pulseVal; |
||||
} |
Loading…
Reference in new issue