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 // Basic example to control scratch with mbed 00002 // Copyright (c) 2008-2009 sford 00003 // Released under the MIT License: http://mbed.org/license/mit 00004 00005 #include "mbed.h" 00006 00007 Serial pc(USBTX, USBRX); 00008 DigitalOut led1(LED1); 00009 00010 // The scratch IO 00011 AnalogIn pin15(p15); 00012 AnalogIn pin16(p16); 00013 AnalogIn pin17(p17); 00014 AnalogIn pin18(p18); 00015 AnalogIn pin19(p19); 00016 AnalogIn pin20(p20); 00017 DigitalIn pin13(p13); 00018 DigitalIn pin14(p14); 00019 00020 /* The format 00021 high byte (sent 1st) 00022 [ 1 | c3:0 | d9:7 ] 00023 low byte 00024 [ 0 | d6:0 ] 00025 */ 00026 void send(int channel, int data) { 00027 int high = 1 << 7 00028 | (channel & 0xF) << 3 00029 | ((data >> 7)& 0x7); 00030 int low = data & 0x7F; 00031 pc.putc(high); 00032 pc.putc(low); 00033 } 00034 00035 int main() { 00036 pc.baud(38400); 00037 while(1) { 00038 pc.getc(); // wait for poll 00039 led1 = !led1; 00040 send(15, 4); // firmware 00041 send(0, pin20 * 1023.0); 00042 send(1, pin19 * 1023.0); 00043 send(2, pin18 * 1023.0); 00044 send(3, pin14 * 1023.0); 00045 send(4, pin17 * 1023.0); 00046 send(5, pin16 * 1023.0); 00047 send(6, pin13 * 1023.0); 00048 send(7, pin15 * 1023.0); 00049 } 00050 }
Generated on Tue Aug 2 2022 23:23:28 by
1.7.2