Last active
December 10, 2015 13:29
-
-
Save willscott/4441540 to your computer and use it in GitHub Desktop.
USB reporting for a MotionSensor'ed DigiSpark
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define USB_CFG_DEVICE_NAME 'M','o','t','i','o','n','S','e','n' | |
#define USB_CFG_DEVICE_NAME_LEN 9 | |
#include <DigiUSB.h> | |
const int timer = 500; | |
short time = 2000; | |
const int ledPin = 0; | |
const int alarmPin = 2; | |
int alarmValue = 0; | |
void setup() { | |
DigiUSB.begin(); | |
pinMode(ledPin, OUTPUT); | |
pinMode(alarmPin, INPUT); | |
} | |
void loop() { | |
DigiUSB.refresh(); | |
if (DigiUSB.available() > 0) { | |
DigiUSB.read(); | |
} | |
if (time-- == 0) { | |
alarmValue = analogRead(alarmPin); | |
if (alarmValue < 100) { | |
digitalWrite(ledPin, HIGH); | |
DigiUSB.print("."); | |
} else { | |
digitalWrite(ledPin, LOW); | |
} | |
DigiUSB.println(alarmValue, DEC); | |
time = timer; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment