Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "ofApp.h"
- #define BUTTON_1 9
- #define BUTTON_2 10
- void ofApp::setup() {
- ofAddListener(arduino.EInitialized, this, &ofApp::setupArduino);
- arduino.connect("/dev/arduino");
- arduino.sendFirmwareVersionRequest(); // workaround for ofArduino/firmata bug
- }
- void ofApp::update() {
- arduino.update();
- }
- void ofApp::setupArduino(const int& version) {
- ofRemoveListener(arduino.EInitialized, this, &ofApp::setupArduino);
- arduino.sendDigitalPinMode(BUTTON_1, ARD_INPUT);
- arduino.sendDigitalPinMode(BUTTON_2, ARD_INPUT);
- ofAddListener(arduino.EDigitalPinChanged, this, &ofApp::digitalPinChanged);
- }
- void ofApp::digitalPinChanged(const int& pinNum) {
- ofLog() << "Digital Pin " << pinNum << " value: " << arduino.getDigital(pinNum) << endl;
- if (pinNum == BUTTON_1) {
- bool pressedNow = arduino.getDigital(BUTTON_1) == 1;
- if (pressedNow) {
- if (!button1WasPressed) {
- button1WasPressed = true;
- count1++;
- ofLog() << "Knop 1 is ingedrukt: " << count1 << endl;
- }
- } else {
- button1WasPressed = false;
- ofLog() << "Knop 1 is NIET ingedrukt" << endl;
- }
- } else if (pinNum == BUTTON_2) {
- bool pressedNow = arduino.getDigital(BUTTON_2) == 1;
- // zelfde voor button2
- }
- }
Add Comment
Please, Sign In to add comment