Skip to content

Instantly share code, notes, and snippets.

@willscott
Last active December 10, 2015 13:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save willscott/4441540 to your computer and use it in GitHub Desktop.
Save willscott/4441540 to your computer and use it in GitHub Desktop.
USB reporting for a MotionSensor'ed DigiSpark
#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