Dan_Ender

Untitled

Jan 23rd, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. OLED disp(SDA, SCL, 8);
  2. extern uint8_t SmallFont[];
  3.  
  4. const int bp0 = 7; //A
  5. const int bp1 = 6; //Б
  6. const int x = 0;
  7. const int y = 0;
  8. int bs0 = LOW;
  9. int bs1 = LOW;
  10.  
  11. void setup() {
  12. disp.begin();
  13. disp.setFont(SmallFont);
  14. pinMode(bp0, INPUT_PULLUP);
  15. pinMode(bp1, INPUT_PULLUP);
  16. }
  17.  
  18. void loop() {
  19. bs0 = digitalRead(bp0);
  20. bs1 = digitalRead(bp1);
  21. Serial.println(bs0);
  22. Serial.println(bs1);
  23. if (question==0) {
  24. question = 1 + (rand() % static_cast<int>(5 - 1 + 1));
  25. disp.clrScr();
  26. disp.print(String(question),x,y);
  27. disp.update();
  28. }
  29. if (bs0==HIGH) {
  30. checkAnsver("A");
  31. } else if (bs1==HIGH) {
  32. checkAnsver("B");
  33. }
  34. }
  35.  
  36. void checkAnsver(String buttonLabel) {
  37. String ansver = getAnsver();
  38. if (ansver.equals(buttonLabel)) {
  39. disp.print("No!",x,y);
  40. } else {
  41. disp.print("Yes!",x,y);
  42. }
  43. question = 0;
  44. }
  45.  
  46. String getAnsver() {
  47. if (question==1) {
  48. return "A";
  49. } else if (question==2) {
  50. return "B";
  51. } else if (question==3) {
  52. return "A";
  53. } else if (question==4) {
  54. return "B";
  55. } else if (question==5) {
  56. return "A";
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment