Last active
January 9, 2020 14:55
-
-
Save andreban/ef1529161658582af9421f15d61db0c4 to your computer and use it in GitHub Desktop.
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
#include <WebUSB.h> | |
WebUSB WebUSBSerial(1 /* https:// */, "rotavo-pwa.firebaseapp.com"); | |
#define Serial WebUSBSerial | |
// These constants won't change. They're used to give names to the pins used: | |
const int analogInPinA = A0; // Analog input pin that the potentiometer is attached to | |
const int analogInPinB = A2; // Analog input pin that the potentiometer is attached to | |
int sensorValueA = 0; // value read from the pot | |
int sensorValueB = 0; // value output to the PWM (analog out) | |
int outputValueA = 0; | |
int outputValueB = 0; | |
int previousValueA = 0; | |
int previousValueB = 0; | |
void setup() { | |
while (!Serial) { | |
; | |
} | |
Serial.begin(9600); | |
Serial.write("Sketch begins.\r\n> "); | |
Serial.flush(); | |
} | |
void loop() { | |
// read the analog in value: | |
sensorValueA = analogRead(analogInPinA); | |
sensorValueB = analogRead(analogInPinB); | |
// map it to the range of the analog out: | |
outputValueA = map(sensorValueA, 0, 1023, 0, 1000); | |
outputValueB = map(sensorValueB, 0, 1023, 0, 1000); | |
if (outputValueA != previousValueA || outputValueB != previousValueB) { | |
// print the results to the Serial Monitor: | |
Serial.print("{x: "); | |
Serial.print(outputValueA); | |
Serial.print(", y:"); | |
Serial.print(outputValueB); | |
Serial.println("}"); | |
previousValueA = outputValueA; | |
previousValueB = outputValueB; | |
} | |
// wait 2 milliseconds before the next loop for the analog-to-digital | |
// converter to settle after the last reading: | |
delay(2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment