![]() This is a "matrix membrane keypad". I have seen 4x4 and 3x4. They are flexible and under $2. The advantage to them is they are more inputs with fewer wires (16 or 12 depending on which you use). There is a wire for each row and each column. How you detect which button is pressed is by using code to scan each row/column combination. So a 3x4 needs 7 wires and a 4x4 needs 8. Which also means, if you need 5 or fewer inputs, just use arcade buttons...(though those would cost more than this). You can put your own stickers over the "buttons" to have special words. The way I have found & figured to code this is to set each row HIGH (digital write) one at a time, then READ each column to see which goes high. pseudocode : Digital write row 1 (whichever pin that is attached to) HIGH if column 1 = HIGH (digital read) then do something if column 2 = HIGH then do something else if column 3 = HIGH then do something different if column 4 - HIGH then do some other thing Digital write row 2 HIGH ... more similar statements for row 2, row 3 , row 4. Could be a good use for a function - "scan keys" I am thinking we have to be careful picking which 8 pins on the micro:bit you use to avoid conflicts. Also, you need an expansion board that gives you access to 8 pins. As well as appropriate dupont wires to make connections. This made me begin to look into arrays in makecode.com (under Advanced) A magic 8 ball is something that uses an array or list of phrases. Shake it and it displays a random item from the list. (could do this with micro:bit and an OLED) You can put a whole bunch of musical notes in an array/list, then use 1 command to play them all, one after the other. But this only works if you play each note for the same duration. The old way would be to have a play command for each note. You might need someplace to store something like a password and someplace to put inputs one at a time...which is an array (or list). Here is a little twist, you dont compare a whole array or a list to see if it matches another, you have to compare EACH element, one at a time. If you try to compare "list1" to "list2"...i think it just looks at the locations, not what is in them So you have to compare "list1 item1" to "list2 item2"...and so on. It is just a matter of choosing the correct code....and maybe a "for loop" or "repeat loop"...AND a nice embedded boolean... "if these two are = AND these two are = AND these 2 are equal....." {i'll do more on that later} So, what project do you have that could use 6-16 possible inputs? -A combination lock/numeric password could be one -Maybe playing music...16 notes? I wonder about a way to do octaves...though I assume you cannot press two of these buttons at the same time, so I would need a second one or arcade buttons to pick the octave. You dont HAVE to use all 16 keys on a 4x4...you could just wire 2 rows. Just some intro thoughts...more later when I make some videos.
0 Comments
More playing around with the #microbit & #makecode. I started looking into using a 0.96" OLED screen for output from a micro:bit (and a 4x4 matrix membrane keypad for inputs)...so here are some beginning thoughts about the OLED... OLED stands for organic light-emitting diode (OLED or organic LED), sometimes known as organic electroluminescent (organic EL) diode. Most often I see two size/resolutions , 128x64 and 128x32 pixels. I have played with the 128x64. The text can be white, blue, yellow, or some combo of those and they cost from $4-7 based on how many you buy on Amazon. I prefer to buy ones with the headers already attached (I don't want to solder). You need an expansion board for the micro:bit because you need access to pins 19 & 20 There are many available, ranging from $7 to $50. They all have different features, as well as different power inputs jacks (jst, micro USB, barrel). Some have pins/sockets to connect to the pins, some have grove connectors... so you will also need the correct wires. Connections... be careful. Always plug GND in first and remove it last (a best practice). Pin 19 is the SCL (serial clock) connection and Pin 20 is the SDA (serial data) connection. The Grove I2C connector (white plugs & cables) has a standard layout. Pin 1 is the SCL signal (serial clock) and Pin 2 is the SDA signal (serial data). Power is Pin 3 and Ground is Pin 4 (usually in the order white, yellow, red, black) Some devices don't adhere to this order. That is why it is good to have a grove-header pin converter cord vs a grove-grove cord Look at the OLED... it goes SDA, SCL, PWR, GND. You need to import the blocks for this device from an extension in makecode { https://makecode.microbit.org/ } Start a "New project” Use either the gear in top right or “Advanced” to get to “Extensions Search for “oled” The second one has more options There are some nuances you have to understand for things to show up correctly. The origin (0,0) is at the top left 128x64 pixels means x pixels numbered from 0-127 and y pixels numbered 0-63 So pixel (0,0) is in top left corner ; pixel (127,63) is in bottom right corner. There are 8 lines of text possible with 24 characters each (text, numbers) BUT... There is a "zoom" feature, and 128x64 is when "zoom=false". Because those 8 lines of text are tiny, they added a "zoom = true" block to double the size of text. When "zoom=true" there are 4 lines of 12 characters. That also means x goes from 0-63 and y from 0-31. Now it is just a matter of what you want to display... Built in sensor data like temperature, light level, accelerometer, sound? Values for variables? (almost forgot-they have an option for "color" -- the options are 0 or 1. see which you prefer) You can make a line graph by plotting pixels. Basically, you will light up pixels at (x, value) and just iterate the x from 0-127 (or 0-63) Two things to think about/do 1) since the origin is top left, i feel it is easier to turn the OLED upside down and iterate x from 127-0 (go by -1)(or 63-0) 2) You need to map your sensor values to the screen size (63 or 31 depending on zoom) You need to know what values your sensor can detect (0-255? 0-1023? 0-10?) There is a block for that...but you also want to round the values (get integer values) Here is an example : I will make some videos soon...
|
Archives
December 2022
Categories |