Guest User

Untitled

a guest
Oct 17th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. #include "ofApp.h"
  2.  
  3. #define BUTTON_1 9
  4. #define BUTTON_2 10
  5.  
  6.  
  7. void ofApp::setup() {
  8. ofAddListener(arduino.EInitialized, this, &ofApp::setupArduino);
  9. arduino.connect("/dev/arduino");
  10. arduino.sendFirmwareVersionRequest(); // workaround for ofArduino/firmata bug
  11.  
  12. }
  13.  
  14. void ofApp::update() {
  15. arduino.update();
  16. }
  17.  
  18. void ofApp::setupArduino(const int& version) {
  19. ofRemoveListener(arduino.EInitialized, this, &ofApp::setupArduino);
  20.  
  21. arduino.sendDigitalPinMode(BUTTON_1, ARD_INPUT);
  22. arduino.sendDigitalPinMode(BUTTON_2, ARD_INPUT);
  23.  
  24. ofAddListener(arduino.EDigitalPinChanged, this, &ofApp::digitalPinChanged);
  25. }
  26.  
  27. void ofApp::digitalPinChanged(const int& pinNum) {
  28. ofLog() << "Digital Pin " << pinNum << " value: " << arduino.getDigital(pinNum) << endl;
  29.  
  30. if (pinNum == BUTTON_1) {
  31. bool pressedNow = arduino.getDigital(BUTTON_1) == 1;
  32. if (pressedNow) {
  33. if (!button1WasPressed) {
  34. button1WasPressed = true;
  35. count1++;
  36. ofLog() << "Knop 1 is ingedrukt: " << count1 << endl;
  37. }
  38. } else {
  39. button1WasPressed = false;
  40. ofLog() << "Knop 1 is NIET ingedrukt" << endl;
  41. }
  42. } else if (pinNum == BUTTON_2) {
  43. bool pressedNow = arduino.getDigital(BUTTON_2) == 1;
  44.  
  45. // zelfde voor button2
  46. }
  47. }
Add Comment
Please, Sign In to add comment