Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 #include "mbed.h" 00002 #include "MCP23S17.h" 00003 00004 DigitalOut OnOffLED(LED1); 00005 DigitalIn OnOffBtn(p30); 00006 PwmOut PwmLED(LED4); 00007 DigitalIn PwmBtnA(p29); 00008 DigitalIn PwmBtnB(p28); 00009 00010 DigitalOut DebugLEDA(LED2); 00011 DigitalOut DebugLEDB(LED3); 00012 00013 SPI spi(p5, p6, p7); 00014 char Opcode = 0x40; 00015 MCP23S17 chip = MCP23S17(spi, p20, Opcode); 00016 00017 00018 00019 int pwm_btn_val; 00020 00021 int main() 00022 { 00023 //Init 00024 OnOffBtn.mode(PullUp); 00025 PwmBtnA.mode(PullDown); 00026 PwmBtnB.mode(PullDown); 00027 00028 //Loop 00029 while(1) { 00030 00031 00032 //OnOff LED code 00033 OnOffLED = !OnOffBtn; 00034 00035 //PWM example 00036 if(!PwmBtnA && !PwmBtnB) 00037 PwmLED = 0.0; 00038 else if(!PwmBtnA && PwmBtnB) 00039 PwmLED = 0.33; 00040 else if(PwmBtnA && !PwmBtnB) 00041 PwmLED = 0.66; 00042 else if(PwmBtnA && PwmBtnB) 00043 PwmLED = 1.0; 00044 00045 00046 //I/O Expander code 00047 // Set all 8 Port A bits to output direction 00048 chip.direction(PORT_A, 0x00); 00049 // Set all 8 Port B bits to input direction 00050 chip.direction(PORT_B, 0xFF); 00051 //action 00052 chip.write(PORT_A, (chip.read(PORT_B)&0x1)?0x80:0x00); 00053 00054 00055 00056 00057 } 00058 }
Generated on Wed Jul 13 2022 21:28:37 by
1.7.2