Example program that exercises most of the capabilities of the mbed application shield (via arduino headers) with ST Nucleo board

Dependencies:   C12832 LM75B MMA7660 mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "C12832.h"
00003 #include "MMA7660.h"
00004 #include "LM75B.h"
00005 
00006 PwmOut red(D5);
00007 PwmOut blue(D8);
00008 PwmOut green(D9);
00009 
00010 int i;
00011 
00012 C12832 lcd ( D11, D13, D12, D7, D10 );
00013 // testing using PB9 instead of D14: yields "undefined identifier"
00014 MMA7660 MMA ( D14, D15 );  // SDA, SCL (defs stolen from temp sensor demo)
00015 LM75B thermometer ( D14, D15 );
00016 
00017 AnalogIn pot1 (A0);
00018 AnalogIn pot2 (A1);
00019 
00020 PwmOut spkr(D6);
00021 
00022 int main() {
00023     float temperature;
00024     float frequency;
00025     float lnSemitone = log ( 2.0 ) / 12.0f;
00026 
00027     while ( 1 ) {
00028         // for (i=0; i<8; i++) {
00029             // red = 1.0 - double ( pot1 );
00030             // blue = i & 2;
00031             // green = i & 4;
00032         // }
00033 
00034         red = MMA.x() * 0.5f + 0.5f;
00035         green = MMA.y() * 0.5f + 0.5f;
00036         blue = float ( pot1 );
00037 
00038         lcd.cls();
00039         lcd.locate ( 1, 1 );
00040         lcd.printf ( "%5.3f %5.3f %5.3f", MMA.x(), MMA.y(), MMA.z() );
00041             
00042         lcd.locate ( 1, 10 );
00043         temperature = thermometer.read();
00044         lcd.printf ( "%6.4f degC", temperature );
00045         
00046         int pitch = ( ( ( temperature - 21.5f ) * 8.0f ) );
00047         frequency = exp ( lnSemitone * pitch ) * 440.0f;
00048         lcd.locate ( 1, 20 );
00049         lcd.printf ( "p: %3d; f: %6.2f", pitch, frequency );
00050         spkr.period ( 1.0f / frequency );
00051         spkr = pot2;  // volume, presumably
00052  
00053         wait ( 0.1 );
00054         
00055     }
00056 }