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

Dependencies:   PCF8574 mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /* 
00002  * Naam:            PCF8574_ButtonPress
00003  *
00004  * Omschrijving:
00005  *                  I2C testprogramma:
00006  *                  -Als PCF8574-Knop# ingedrukt: PCF8574-Led# aan
00007  *                  -Als PCF8574-Knop# losgelaten: PCF8574-Led# uit.
00008  *
00009  * Aanmaakdatum:    05 april 2016
00010  * 
00011  * Geschreven door: Marout Yasuo Sluijter-Borms
00012  * 
00013  * Copyright (c) 2016, MYSB, The Manhattan Project
00014  * Zie einde programma /  See end of program.
00015  */ 
00016  
00017 /*  Libraries en classes insluiten  */
00018 #include "mbed.h"
00019 #include "PCF8574.h"
00020 
00021 /*  Definieer seriële poorten       */
00022 Serial pc(USBTX, USBRX);            //  tx, rx communicatie met PC terminal via USB.
00023 PCF8574 pcf0( p9, p10, 0x72);      //  Eerste PCF8574 chip
00024 //PCF8574 pcf1( p28, p37, 0x74);      //  Tweede PCF8574 chip
00025 
00026 
00027 /*  Definieer digitale IO           */
00028 DigitalOut led(LED2);               //  Led 2 op mbed is signaal 'Initialisatie klaar'.
00029 
00030 /*  Definieer Analoge IO            */
00031 
00032 /*  Definieer globale variabelen    */
00033 char DataIn;                        //  Data ingelezen van PCF8574
00034 char DataOut;                       //  Data te schrijven naar PCF8574
00035 
00036 /*  Definieer globale constanten    */
00037 
00038 /*  Definieer functie   */
00039 
00040 /*  Start hoofprogramma             */
00041 
00042 int main()
00043 {
00044     while (1)
00045         {
00046             DataIn = pcf0.read();       //  lees inputs uit
00047             DataOut = DataIn >> 4;      //  schuif knoppen naar leds
00048             DataOut = DataOut + 0xf0;   //  zet leds uit en knoppen uitleesbaar (out = high)
00049             pcf0.write(DataOut);
00050         }       //  endwhile
00051 }       //  endmain
00052 /*
00053  * Permission is hereby granted, free of charge, to any person obtaining a copy
00054  * of this software and associated documentation files (the "Software"), to deal
00055  * in the Software without restriction, including without limitation the rights
00056  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00057  * copies of the Software, and to permit persons to whom the Software is
00058  * furnished to do so, subject to the following conditions:
00059  *
00060  * The above copyright notice and this permission notice shall be included in
00061  * all copies or substantial portions of the Software.
00062  *
00063  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00064  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00065  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00066  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00067  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00068  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00069  * THE SOFTWARE.
00070  */