Skip to content

Instantly share code, notes, and snippets.

@giljr
Created April 8, 2017 01:32
Show Gist options
  • Save giljr/522e2ed882b96c4b57bc96b8773f7e66 to your computer and use it in GitHub Desktop.
Save giljr/522e2ed882b96c4b57bc96b8773f7e66 to your computer and use it in GitHub Desktop.
#include <FlexiTimer2.h> // use timer for sampling to get even time base for data
#define INVERTED_INPUT_PIN 10
const int READ_PWM_PIN = A0;
const int READ_FILTERED_PIN = A1;
const int READ_DIGITAL_PIN = 8;
int inverted_value = 0;
void setup() {
Serial.begin(115200); // initialize serial communications (to match that used by PlotNValues.pde)
pinMode(INVERTED_INPUT_PIN, OUTPUT);
FlexiTimer2::set(10, sample);
FlexiTimer2::start();
}
void loop() {
for (inverted_value = 0; inverted_value <= 255; inverted_value += 10) {
analogWrite(INVERTED_INPUT_PIN, inverted_value);
delay(100);
}
for (inverted_value = 255; inverted_value >= 0; inverted_value -= 10) {
analogWrite(INVERTED_INPUT_PIN, inverted_value);
delay(100);
}
}
// sample values and pipe to processing
void sample() {
String result = "";
Serial.println(result + inverted_value + "," + analogRead(READ_PWM_PIN) + "," + analogRead(READ_FILTERED_PIN) + "," + digitalRead(READ_DIGITAL_PIN));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment