The Dallas/Maxim DS2413 is a 1-wire device that has two I/O ports for input or open-drain output. You can use the 1-wire commands of MMbasic and a selected device pin to control a number of 1-wire devices, adding a DS2413 to a CGMICROBOARD2 (in this case) lets you expand that single pin to two per DS2413 added.
This project connects a DS2413 to pin 17 of a CGMICROBOARD2. Two LEDs are connected to the ports of the DS2413. An LCD with touch screen shows the LED status, as well as the graphic button control.
Black jumper wires connect ground to the solderless breadboard. The red jumper wire connects 3.3V to the breadboard.
The white jumper wire connects uM17 to the data connection of the DS2413 and is also pulled up to 3.3V through a 10k resistor.
The ports of the DS2413, when set to outputs, are open-drain. The LEDs are connected on one side to a resistor to 3.3V and on the other end to the output port of the DS2413. When turned on the DS2413 output acts as a switch to ground, illuminating the LED.
Above you can see that the code running on the CGMICROBOARD2 creates two LED controls and two BUTTONS. The green LED is enabled. Both the actual LED and the on-screen LED are on.
In the image above, both LEDs are turned on. The buttons below the LED indicators on the LCD toggle the state of the LEDs.
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 |
' -------------------------------------------------------------- ' CGMICROBOARD2 ' 2.4" SPI 240X320 LCD display w/touch ' OPTION LCDPANEL ILI9341, L, 21, 22, 23 ' OPTION TOUCH 18, 14 ' -------------------------------------------------------------- OPTION explicit DIM onewirepin = 17 DIM ledoff = 1 DIM ledon = 0 DIM greenled = ledoff DIM yellowled = ledoff DIM ack1 DIM stat1 DIM touched DIM greenstate DIM yellowstate PAUSE 100 ' Set interrupt that processes control touches GUI INTERRUPT PenDown COLOR RGB(255,255,255),RGB(120,120,120) FONT 3 CLS ' Make status LEDs on LCD GUI LED #1, "Green LED", 60, 20, 20, RGB(0,255,0) GUI LED #2, "Yellow LED", 60, 60, 20, RGB(255,255,0) GUI BUTTON #3, "Green LED", 50, 120, 200, 40, RGB(0,255,0), RGB(120,120,120) GUI BUTTON #4, "Yellow LED", 50, 180, 200, 40, RGB(255,255,0), RGB(120,120,120) DO ONEWIRE Write onewirepin, 1, 4, &hCC, &h5A, greenled + yellowled*2, &hFF - greenled - yellowled*2 ONEWIRE READ onewirepin, 0, 2, ack1, stat1 ONEWIRE RESET onewirepin PAUSE 500 LOOP END ' -------------------------------------------------------------- ' Process touch ' -------------------------------------------------------------- SUB PenDown touched = TOUCH(REF) IF touched = 3 THEN greenstate = CTRLVAL(1) IF greenstate = 0 THEN CTRLVAL(1) = 1 greenled = ledon ELSE CTRLVAL(1) = 0 greenled = ledoff ENDIF ENDIF IF touched = 4 THEN yellowstate = CTRLVAL(2) IF yellowstate = 0 THEN CTRLVAL(2) = 1 yellowled = ledon ELSE CTRLVAL(2) = 0 yellowled = ledoff ENDIF ENDIF END SUB |