mbed code Inductive_Sensor_Jasper for Bsc paper
Dependencies: Bob DS1825 LDC1101 SDFileSystem mbed
Fork of Inductive_Sensor by
main.cpp
- Committer:
- bobgiesberts
- Date:
- 2015-12-12
- Revision:
- 1:22c272515015
- Parent:
- 0:e81b68888268
- Child:
- 2:1a203732fc95
File content as of revision 1:22c272515015:
#include "mbed.h" #include "LDC1101.h" #include "SDFileSystem.h" #include <iostream> using namespace std; // Feedback on console Serial pc(USBTX, USBRX); // Feedback with leds DigitalOut redled(PTB0); // Red DigitalOut greenled(PTB1); // Green void flash(int n){ for(int i = 0; i < n*2; i++){ redled = 1-redled; greenled = 1-greenled; wait(0.2); } } // Main action int main(void){ pc.printf("5x knipperen...\n"); flash(5); // --- Connection to LDC1101 pc.printf("Contact maken met LDC1101..."); LDC1101 ldc(PTC6, PTC7, PTC5, PTC4, 120E-12, 6000000); // mosi, miso, sck, cs, capacitor, f_CLKIN pc.printf("success!\n"); // --- Connection to SD card // Enable PTC3 DigitalOut sd_pin(PTC3); sd_pin = 1; // Load SD card SDFileSystem SD(PTD6, PTD7, PTD5, PTD4, "sd"); // mosi, miso, sclk, cs, sd_name // something with card detect? // if(PTE0 == 1) mkdir("/sd/mydir", 0777); FILE *fp = fopen("/sd/mydir/sdtest.txt", "w"); if(fp == NULL) { error("ERROR: Could not open file for write\n"); } fprintf(fp, "Start writing the SD card!\r\n"); fclose(fp); while(1) { // feedback with LEDs flash(1); // Feedback in putty pc.printf("%4.0f",ldc.get_raw_l()); pc.printf(", %f \r\n", 1000000*ldc.getInductance()); // Store in SD_card fprintf(fp, "Doet het!\r\n"); wait_ms(250); } // On exit fclose(fp); }