First version with a button and added the Blinker library to the source root.
This commit is contained in:
parent
d74bcbb2b6
commit
15e33b531f
9 changed files with 246 additions and 31 deletions
44
Digispark_Passkey/Blinker/Blinker.cpp
Normal file
44
Digispark_Passkey/Blinker/Blinker.cpp
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
#include <Blinker.h>
|
||||||
|
|
||||||
|
Blinker::Blinker(int pin) {
|
||||||
|
_blinkPin = pin;
|
||||||
|
_highDelay = 500;
|
||||||
|
_lowDelay = 500;
|
||||||
|
_lastBlink = 0;
|
||||||
|
_blinkState = false;
|
||||||
|
_running = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Blinker::setDelay(uint32_t d) {
|
||||||
|
_highDelay = d;
|
||||||
|
_lowDelay = d;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Blinker::setDelay(uint32_t h, uint32_t l) {
|
||||||
|
_highDelay = h;
|
||||||
|
_lowDelay = l;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Blinker::blink() {
|
||||||
|
uint32_t diff = millis() - _lastBlink;
|
||||||
|
uint32_t blinkDelay = _blinkState ? _highDelay : _lowDelay;
|
||||||
|
if (diff >= blinkDelay) {
|
||||||
|
_lastBlink = millis() - (diff - blinkDelay); // Account for any delay in calling blink
|
||||||
|
_blinkState = !_blinkState;
|
||||||
|
if (_running) {
|
||||||
|
digitalWrite(_blinkPin, _blinkState ? HIGH : LOW);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Blinker::start() {
|
||||||
|
pinMode(_blinkPin, OUTPUT);
|
||||||
|
_running = true;
|
||||||
|
_lastBlink = millis();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Blinker::stop(bool idleState) {
|
||||||
|
_running = false;
|
||||||
|
_blinkState = idleState;
|
||||||
|
digitalWrite(_blinkPin, _blinkState);
|
||||||
|
}
|
||||||
28
Digispark_Passkey/Blinker/Blinker.h
Normal file
28
Digispark_Passkey/Blinker/Blinker.h
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
#ifndef _BLINKER_H
|
||||||
|
#define _BLINKER_H
|
||||||
|
|
||||||
|
#if (ARDUINO >= 100)
|
||||||
|
# include <Arduino.h>
|
||||||
|
#else
|
||||||
|
# include <WProgram.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
class Blinker {
|
||||||
|
private:
|
||||||
|
int _blinkPin;
|
||||||
|
uint32_t _highDelay;
|
||||||
|
uint32_t _lowDelay;
|
||||||
|
uint32_t _lastBlink;
|
||||||
|
boolean _blinkState;
|
||||||
|
boolean _running;
|
||||||
|
|
||||||
|
public:
|
||||||
|
Blinker(int pin);
|
||||||
|
void setDelay(uint32_t d);
|
||||||
|
void setDelay(uint32_t h, uint32_t l);
|
||||||
|
void blink();
|
||||||
|
void start();
|
||||||
|
void stop(bool idleState = LOW);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
30
Digispark_Passkey/Blinker/LICENSE.md
Normal file
30
Digispark_Passkey/Blinker/LICENSE.md
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
|
||||||
|
Copyright (c) 2015, Majenko Technologies
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
|
are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright notice, this
|
||||||
|
list of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||||
|
list of conditions and the following disclaimer in the documentation and/or
|
||||||
|
other materials provided with the distribution.
|
||||||
|
|
||||||
|
* Neither the name of Majenko Technologies nor the names of its
|
||||||
|
contributors may be used to endorse or promote products derived from
|
||||||
|
this software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||||
|
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||||
|
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
|
||||||
9
Digispark_Passkey/Blinker/README.md
Normal file
9
Digispark_Passkey/Blinker/README.md
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
Blinker Library
|
||||||
|
===============
|
||||||
|
|
||||||
|
This very simple little library will cause an output
|
||||||
|
to "blink" - that is repeatedly go HIGH then LOW with a
|
||||||
|
requested delay.
|
||||||
|
|
||||||
|
The operation is completely non-blocking, so you can
|
||||||
|
blink an output while doing other things.
|
||||||
54
Digispark_Passkey/Blinker/examples/BlinkTest/BlinkTest.ino
Normal file
54
Digispark_Passkey/Blinker/examples/BlinkTest/BlinkTest.ino
Normal file
|
|
@ -0,0 +1,54 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2015, Majenko Technologies
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without modification,
|
||||||
|
* are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright notice, this
|
||||||
|
* list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* * Redistributions in binary form must reproduce the above copyright notice, this
|
||||||
|
* list of conditions and the following disclaimer in the documentation and/or
|
||||||
|
* other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* * Neither the name of Majenko Technologies nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived from
|
||||||
|
* this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||||
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||||
|
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <Blinker.h>
|
||||||
|
|
||||||
|
// Most boards have an LED on pin 13. Let's blink it.
|
||||||
|
Blinker blinker(13);
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
// The blinker defaults to 500ms delay, which is a 1 second period blinking.
|
||||||
|
// Let's make it faster - say 250ms delay.
|
||||||
|
blinker.setDelay(250);
|
||||||
|
|
||||||
|
// There is also an asymetric blink delay version which takes two delay values,
|
||||||
|
// one for the ON time and one for the OFF time:
|
||||||
|
// blinker.setDelay(50, 950);
|
||||||
|
|
||||||
|
// Start the blinker blinking. There's also a blinker.stop() function.
|
||||||
|
blinker.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
// As long as you keep calling this method the output will toggle
|
||||||
|
// with the requested delay. It's non-blocking so you can do othe
|
||||||
|
// things while blinking.
|
||||||
|
blinker.blink();
|
||||||
|
}
|
||||||
13
Digispark_Passkey/Blinker/library.json
Normal file
13
Digispark_Passkey/Blinker/library.json
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
{
|
||||||
|
"name": "Blinker",
|
||||||
|
"keywords": "led, blink",
|
||||||
|
"description": "Non-blocking LED blinking class",
|
||||||
|
"repository":
|
||||||
|
{
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/MajenkoLibraries/Blinker"
|
||||||
|
},
|
||||||
|
"version": "1.0.3",
|
||||||
|
"frameworks": "arduino",
|
||||||
|
"platforms": "*"
|
||||||
|
}
|
||||||
10
Digispark_Passkey/Blinker/library.properties
Normal file
10
Digispark_Passkey/Blinker/library.properties
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
name=Blinker
|
||||||
|
version=1.0.4
|
||||||
|
author=Matt Jenkins
|
||||||
|
maintainer=Matt Jenkins <matt@majenko.co.uk>
|
||||||
|
sentence=Blink an output in different patterns
|
||||||
|
paragraph=Blinker Library\n===============\n\nThis very simple little library will cause an output\nto "blink" - that is repeatedly go HIGH then LOW with a \nrequested delay.\n\nThe operation is completely non-blocking, so you can\nblink an output while doing other things.\n
|
||||||
|
url=https://github.com/MajenkoLibraries/Blinker
|
||||||
|
category=Signal Input/Output
|
||||||
|
architectures=*
|
||||||
|
includes=Blinker.h
|
||||||
1
Digispark_Passkey/Blinker/uecide.json
Normal file
1
Digispark_Passkey/Blinker/uecide.json
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
{"name":"Blinker","provides":"Blinker.h","license":"LICENSE.md","readme":"README.md","description":"Blink an output in different patterns","category":"IO","subcategory":"Digital","maintainer":"Matt Jenkins <matt@majenko.co.uk>","version":"1.0.4","family":"all","core":"all","install":{"examples":"\/","library.properties":"\/","src":"\/"}}
|
||||||
|
|
@ -1,56 +1,82 @@
|
||||||
#include "Blinker.h"
|
#include "Blinker.h"
|
||||||
#include "DigiKeyboard.h"
|
#include "DigiKeyboard.h"
|
||||||
#include "ezButton.h"
|
|
||||||
|
|
||||||
int ACTION_PIN = 0;
|
// the button pin
|
||||||
int LED_PIN = 1;
|
#define BUTTON_PIN 0
|
||||||
|
// the LED pin
|
||||||
|
#define LED_PIN 1
|
||||||
|
// the pause after last button press before executing a command
|
||||||
|
#define PAUSE 2000
|
||||||
|
|
||||||
|
// local variables
|
||||||
|
unsigned long last;
|
||||||
|
unsigned int count;
|
||||||
|
|
||||||
|
// create blinker
|
||||||
Blinker blinker(LED_PIN);
|
Blinker blinker(LED_PIN);
|
||||||
ezButton button(ACTION_PIN);
|
|
||||||
|
|
||||||
char *passwords[] = {
|
// the list of available passwords
|
||||||
"0qMpI7Af06Z4XnMDhzXROnEgtuxPsCPLiBJT90Rb1F2BZKCmIhpLOdxtBpurUa9Tg",
|
const char *passwords[] = {
|
||||||
"1qMpI7Af06Z4XnMDhzXROnEgtuxPsCPLiBJT90Rb1F2BZKCmIhpLOdxtBpurUa9Tg",
|
"PASSWORD1",
|
||||||
"2qMpI7Af06Z4XnMDhzXROnEgtuxPsCPLiBJT90Rb1F2BZKCmIhpLOdxtBpurUa9Tg",
|
"PASSWORD2",
|
||||||
"3qMpI7Af06Z4XnMDhzXROnEgtuxPsCPLiBJT90Rb1F2BZKCmIhpLOdxtBpurUa9Tg"
|
"PASSWORD3",
|
||||||
|
"PASSWORD4"
|
||||||
};
|
};
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
// set button pin to high
|
||||||
|
pinMode(BUTTON_PIN, INPUT);
|
||||||
|
digitalWrite(BUTTON_PIN, HIGH);
|
||||||
|
|
||||||
|
// light up the LED for a second to show that passkey is ready
|
||||||
pinMode(LED_PIN, OUTPUT);
|
pinMode(LED_PIN, OUTPUT);
|
||||||
digitalWrite(LED_PIN, HIGH);
|
digitalWrite(LED_PIN, HIGH);
|
||||||
delay(1000);
|
delay(1000);
|
||||||
digitalWrite(LED_PIN, LOW);
|
digitalWrite(LED_PIN, LOW);
|
||||||
|
|
||||||
|
// set blink effect (ON, OFF) in milliseconds
|
||||||
blinker.setDelay(25, 10000);
|
blinker.setDelay(25, 10000);
|
||||||
blinker.start();
|
blinker.start();
|
||||||
button.setCountMode(COUNT_RISING);
|
|
||||||
button.setDebounceTime(0);
|
// initialize HID
|
||||||
DigiKeyboard.delay(0);
|
DigiKeyboard.delay(0);
|
||||||
DigiKeyboard.sendKeyStroke(0);
|
DigiKeyboard.sendKeyStroke(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
// start LED blink effect
|
||||||
blinker.blink();
|
blinker.blink();
|
||||||
button.loop();
|
|
||||||
|
|
||||||
/*digitalWrite(LED_PIN, HIGH);
|
// read button state
|
||||||
delay(25);
|
if (digitalRead(BUTTON_PIN) == LOW) {
|
||||||
digitalWrite(1, LOW);
|
// button is pressed
|
||||||
delay(10000);*/
|
last = millis();
|
||||||
|
count++;
|
||||||
if(button.isPressed()) {
|
// wait until button is released
|
||||||
//DigiKeyboard.println("Hello World!");
|
while(digitalRead(BUTTON_PIN) == LOW) {
|
||||||
/*DigiKeyboard.println(passwords[0]);
|
delay(1);
|
||||||
DigiKeyboard.println(passwords[1]);
|
}
|
||||||
DigiKeyboard.println(passwords[2]);
|
|
||||||
DigiKeyboard.println(passwords[3]);*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long count = button.getCount();
|
// wait PAUSE time before executing a command
|
||||||
|
if (count > 0 && (millis() - last) >= PAUSE) {
|
||||||
// press button five times to get a password
|
// the switch case is the number of button presses
|
||||||
if(count == 5) {
|
switch(count) {
|
||||||
//DigiKeyboard.println(count);
|
case 1:
|
||||||
DigiKeyboard.println(passwords[0]);
|
DigiKeyboard.println(passwords[0]);
|
||||||
button.resetCount();
|
break;
|
||||||
|
case 2:
|
||||||
|
DigiKeyboard.println(passwords[1]);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
DigiKeyboard.println(passwords[2]);
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
DigiKeyboard.println(passwords[3]);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
count = 0; // reset the counter
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue