OBJECTIVE: To practice creating an interactive system on your own by finding your own resources. To build skills in life long learning and problem solving.
MATERIALS USED:
- Elegoo UNO R3
- 1x 4x4 Membrane Switch
- 1x LCD Display
- 1x 10k Pentiometer
- Jumper Wires
Just One Thing: Communication
You say yes, your friend says no. A third person, in the distance, only sees a state of agreement or disagreement between the two of you. This is the interaction I wanted to capture in this assignment.
First, a question is launched and then each player submits their opinion (yes, no, or a neutral option). After that, the system compares these inputs and, instead of the players' opinions, it broadcasts whether they agreed, or disagreed. The disagreement broadcast also includes the combination of maybe with either yes or no.
Ideally, the system would then increment question complexity, or, in other words, the questions would become more and more serious/in-depth/interesting. Audience members wouldn't be able to tell what player submitted which opinion, but they would be able to see the general comparison. Players, on the other hand, would have a general idea of what the other player submitted.
Orrrrrr, so that was the goal, but every-time I tried to store and compare my key from membrane input with my input from the serial monitor, it failed miserably. In an attempt to show how my code works, I actually had to go against that logic of not showing a player's opinion, just to verify that each player had at least participated.
Still, here's what I got:
First, a question is launched and then each player submits their opinion (yes, no, or a neutral option). After that, the system compares these inputs and, instead of the players' opinions, it broadcasts whether they agreed, or disagreed. The disagreement broadcast also includes the combination of maybe with either yes or no.
Ideally, the system would then increment question complexity, or, in other words, the questions would become more and more serious/in-depth/interesting. Audience members wouldn't be able to tell what player submitted which opinion, but they would be able to see the general comparison. Players, on the other hand, would have a general idea of what the other player submitted.
Orrrrrr, so that was the goal, but every-time I tried to store and compare my key from membrane input with my input from the serial monitor, it failed miserably. In an attempt to show how my code works, I actually had to go against that logic of not showing a player's opinion, just to verify that each player had at least participated.
Still, here's what I got:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | #include <LiquidCrystal.h> #include <Keypad.h> /************************************************* * Pins & Pre-Setup *************************************************/ // MEMBRANE SWITCH // 4 x 4 membrane switch, but shortened to 2 x 3 // define key press as symbols for feedback const byte ROWS = 2; const byte COLS = 3; //define the cymbols on the buttons of the keypads char feedback[ROWS][COLS] = { {'1','2','3'}, {'4','5','6'} }; // Refers to and uses digital pins 2 - 9 // See schematic for explanation of membrane switch wiring // Self-Note: Did not use 3,4, or 8. 3-4 are last two rows, 8 is letter column byte rowPins[ROWS] = {2,6}; byte colPins[COLS] = {5, 4, 3}; // Create Keypad using feedback symbols, digital pins, and the original row/col setup Keypad membraneKeypad = Keypad( makeKeymap(feedback), rowPins, colPins, ROWS, COLS); // LCD DISPLAY // Set up LCD Pins LiquidCrystal lcd(7,8,9,10,11,12); // INPUT VARIABLES // player input char membraneKey = 'n'; char serialInput = 'n'; // questions // can't seem to find better way to handle string arrays(?) // don't put much thought into these String question1 = "Do you like dogs?"; String question2 = "Do you like people?"; String question3 = "Is chocolate better than vanilla?"; String question4 = "If possible, would you revive dinosaurs?"; String question5 = "If possible, would you dramatically change the course of history?"; // count to loop through questions // has to be stored here to keep track place static int count = 0; /************************************************* * Setup *************************************************/ void setup() { Serial.begin(9600); // LCD Startup Sequence lcd.begin(16,2); lcd.print("(OvO) hellowl!"); delay(3000); lcd.clear(); lcd.print("Take Note:"); delay(1000); lcd.setCursor(0, 2); lcd.print("1:YES "); lcd.print("2:NO "); lcd.print("3:EH"); lcd.setCursor(0, 1); // Begin questions Serial.print(question1); Serial.println(""); } /************************************************* * Loop *************************************************/ void loop() { // HANDLING MEMBRANE CONTROL // Assign character based off of membrane input // If serial is entered, also assign that character membraneKey = membraneKeypad.getKey(); if(Serial.available() > 0) { serialInput = Serial.read(); // This wouldn't be in finished version if (serialInput == '1') { Serial.println("CP Player says yes!"); } else if (serialInput == '2') { Serial.println("CP Player says no!"); }else if (serialInput == '3') { Serial.println("CP Player doesn't feel strongly one way or the other!"); } } // MAKE SURE SERIAL INPUT IS ENTERED FIRST OR ELSE IT WONT WORK ! // I don't know how to get around this issue currently / Also wouldn't be in final if (membraneKey) { if (membraneKey == '1') { Serial.println("Switch Player says yes!"); } else if (membraneKey == '2') { Serial.println("Switch Player says no!"); }else if (membraneKey == '3') { Serial.println("Switch Player doesn't feel strongly one way or the other!"); } checkThatCount(); doWeAgree(); } } /************************************************* * MY FUNCTIONS *************************************************/ // Runs through loops to see what count currently equals // Then either adds or resets count based on that integer void checkThatCount() { if (count == 0) { Serial.println(question2); } else if (count == 1) { Serial.println(question3); } else if (count == 2) { Serial.println(question4); } else if (count == 3) { Serial.println(question5); } else if (count >= 4) { count = 0; Serial.println(question1); } count++; } void doWeAgree() { lcd.clear(); if (membraneKey == serialInput) { lcd.print("They both"); lcd.setCursor(0, 2); lcd.print("agreed!"); } else if (membraneKey != serialInput) { lcd.print("They both"); lcd.setCursor(0, 2); lcd.print("disagreed!"); } } |
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.