Skip to content

Instantly share code, notes, and snippets.

@willscott willscott/MotionSensor.ino
Last active Dec 10, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.