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
- Committer:
- jeroenkoster
- Date:
- 2018-12-04
- Revision:
- 1:cedd9360f5c7
- Parent:
- 0:c2ab34dc9018
- Child:
- 3:74f042e3ec10
File content as of revision 1:cedd9360f5c7:
#include "mbed.h" //Init Pins SPI spi(D11, D12, D13); DigitalOut cs(D10, 1); void init() { cs = 0; spi.write(0x46); // Select IODIR spi.write(0x00); // 0000 = Set all to output spi.write(0x00); // Deselect the device cs = 1; } void setLed(int i) { cs = 0; spi.write(0x46); spi.write(0x09); int mask = 1; int writeValue = 255; writeValue ^= mask << i; spi.write(writeValue); cs = 1; } int readButton() { cs = 0; spi.write(0x47); spi.write(0x09); int misoOutput = spi.write(0x00); cs = 1; misoOutput = misoOutput & 192; printf("output miso: %d", misoOutput); if (misoOutput == 128) { // S1 pressed return 1; } else if (misoOutput == 64) { // S2 pressed return 5; } return 0; } int main() { cs = 1; printf("Initializing. \n\r"); init(); printf("Setting Led. \n\r"); // Select the device by seting chip select low int led = 0; printf("Starting \n\r"); while (true) { setLed(led); led = (led + readButton()) % 6; wait(0.1); } }