Read status of buttons on D5-D7 of PCF8574. Turn on corresponding led D0-D3.

Dependencies:   PCF8574 mbed

Committer:
hainjedaf
Date:
Tue Apr 05 12:55:58 2016 +0000
Revision:
1:85d249817f55
Parent:
0:c862449fe089
If button (D5-D8) is pressed on PCF8574, Led (D0-D3) will turn on.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hainjedaf 0:c862449fe089 1 /*
hainjedaf 0:c862449fe089 2 * Naam: PCF8574_ButtonPress
hainjedaf 0:c862449fe089 3 *
hainjedaf 0:c862449fe089 4 * Omschrijving:
hainjedaf 0:c862449fe089 5 * I2C testprogramma:
hainjedaf 0:c862449fe089 6 * -Als PCF8574-Knop# ingedrukt: PCF8574-Led# aan
hainjedaf 0:c862449fe089 7 * -Als PCF8574-Knop# losgelaten: PCF8574-Led# uit.
hainjedaf 0:c862449fe089 8 *
hainjedaf 1:85d249817f55 9 * Aanmaakdatum: 05 april 2016
hainjedaf 0:c862449fe089 10 *
hainjedaf 0:c862449fe089 11 * Geschreven door: Marout Yasuo Sluijter-Borms
hainjedaf 0:c862449fe089 12 *
hainjedaf 0:c862449fe089 13 * Copyright (c) 2016, MYSB, The Manhattan Project
hainjedaf 0:c862449fe089 14 * Zie einde programma / See end of program.
hainjedaf 0:c862449fe089 15 */
hainjedaf 0:c862449fe089 16
hainjedaf 0:c862449fe089 17 /* Libraries en classes insluiten */
hainjedaf 0:c862449fe089 18 #include "mbed.h"
hainjedaf 0:c862449fe089 19 #include "PCF8574.h"
hainjedaf 0:c862449fe089 20
hainjedaf 0:c862449fe089 21 /* Definieer seriële poorten */
hainjedaf 0:c862449fe089 22 Serial pc(USBTX, USBRX); // tx, rx communicatie met PC terminal via USB.
hainjedaf 1:85d249817f55 23 PCF8574 pcf0( p9, p10, 0x72); // Eerste PCF8574 chip
hainjedaf 1:85d249817f55 24 //PCF8574 pcf1( p28, p37, 0x74); // Tweede PCF8574 chip
hainjedaf 0:c862449fe089 25
hainjedaf 0:c862449fe089 26
hainjedaf 0:c862449fe089 27 /* Definieer digitale IO */
hainjedaf 0:c862449fe089 28 DigitalOut led(LED2); // Led 2 op mbed is signaal 'Initialisatie klaar'.
hainjedaf 0:c862449fe089 29
hainjedaf 0:c862449fe089 30 /* Definieer Analoge IO */
hainjedaf 0:c862449fe089 31
hainjedaf 0:c862449fe089 32 /* Definieer globale variabelen */
hainjedaf 0:c862449fe089 33 char DataIn; // Data ingelezen van PCF8574
hainjedaf 0:c862449fe089 34 char DataOut; // Data te schrijven naar PCF8574
hainjedaf 0:c862449fe089 35
hainjedaf 0:c862449fe089 36 /* Definieer globale constanten */
hainjedaf 1:85d249817f55 37
hainjedaf 1:85d249817f55 38 /* Definieer functie */
hainjedaf 0:c862449fe089 39
hainjedaf 0:c862449fe089 40 /* Start hoofprogramma */
hainjedaf 0:c862449fe089 41
hainjedaf 0:c862449fe089 42 int main()
hainjedaf 0:c862449fe089 43 {
hainjedaf 0:c862449fe089 44 while (1)
hainjedaf 0:c862449fe089 45 {
hainjedaf 1:85d249817f55 46 DataIn = pcf0.read(); // lees inputs uit
hainjedaf 1:85d249817f55 47 DataOut = DataIn >> 4; // schuif knoppen naar leds
hainjedaf 1:85d249817f55 48 DataOut = DataOut + 0xf0; // zet leds uit en knoppen uitleesbaar (out = high)
hainjedaf 0:c862449fe089 49 pcf0.write(DataOut);
hainjedaf 0:c862449fe089 50 } // endwhile
hainjedaf 0:c862449fe089 51 } // endmain
hainjedaf 0:c862449fe089 52 /*
hainjedaf 0:c862449fe089 53 * Permission is hereby granted, free of charge, to any person obtaining a copy
hainjedaf 0:c862449fe089 54 * of this software and associated documentation files (the "Software"), to deal
hainjedaf 0:c862449fe089 55 * in the Software without restriction, including without limitation the rights
hainjedaf 0:c862449fe089 56 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
hainjedaf 0:c862449fe089 57 * copies of the Software, and to permit persons to whom the Software is
hainjedaf 0:c862449fe089 58 * furnished to do so, subject to the following conditions:
hainjedaf 0:c862449fe089 59 *
hainjedaf 0:c862449fe089 60 * The above copyright notice and this permission notice shall be included in
hainjedaf 0:c862449fe089 61 * all copies or substantial portions of the Software.
hainjedaf 0:c862449fe089 62 *
hainjedaf 0:c862449fe089 63 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
hainjedaf 0:c862449fe089 64 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
hainjedaf 0:c862449fe089 65 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
hainjedaf 0:c862449fe089 66 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
hainjedaf 0:c862449fe089 67 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
hainjedaf 0:c862449fe089 68 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
hainjedaf 0:c862449fe089 69 * THE SOFTWARE.
hainjedaf 0:c862449fe089 70 */