Skip to content

Instantly share code, notes, and snippets.

@andreban
Last active January 6, 2020 16:39
Show Gist options
  • Save andreban/99f57744646ad664a858961541064235 to your computer and use it in GitHub Desktop.
Save andreban/99f57744646ad664a858961541064235 to your computer and use it in GitHub Desktop.
/*
* Copyright 2020 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <WebUSB.h>
/**
* Follow the instructions on https://github.com/webusb/arduino/ to install
* the library and get the Arduino IDE to build and install it correctly.
*/
WebUSB WebUSBSerial(1 /* https:// */, "webusb-horn.firebaseapp.com");
#define Serial WebUSBSerial
const int ledPin = 13;
const int buttonPin = 2;
int previousButtonState = 0;
void setup() {
while (!Serial) {
;
}
Serial.begin(9600);
Serial.write("Sketch begins.\r\n> ");
Serial.flush();
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
}
void loop() {
if (Serial) {
int buttonState = digitalRead(buttonPin);
if (buttonState != previousButtonState) {
if (buttonState == HIGH) {
digitalWrite(ledPin, HIGH);
Serial.write("ON\r\n");
} else {
digitalWrite(ledPin, LOW);
Serial.write("OFF\r\n");
}
Serial.flush();
}
previousButtonState = buttonState;
delay(10);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment