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.
Dependencies: C12832 SWSPI mbed
Fork of IonScan_DO_SPI by
pos.cpp
00001 #include "mbed.h" 00002 #include "C12832.h" 00003 #include "SWSPI.h" 00004 #include <cmath> 00005 00006 SWSPI spi(PC_4,PC_12,PA_13); // MOSI"bidon" / MISO /CLK 00007 00008 C12832 lcd(D11, D13, D12, D7, D10); 00009 00010 DigitalOut CS(PA_14); 00011 00012 00013 InterruptIn index(PA_15); 00014 00015 double cpt_fall=0; 00016 00017 float distance=0,cpt_rise=0,compteur_index=0; 00018 00019 short cpt=0; 00020 00021 long x=0,x1=0,pas,RAZ = 0,pos_finale=0, pos_initiale=0; 00022 00023 00024 00025 void pressed() 00026 { 00027 if (x >= 3000) { 00028 cpt_rise++; 00029 } 00030 if (x <= 1000) { 00031 cpt_rise--; 00032 } 00033 00034 } 00035 00036 void released() 00037 { 00038 cpt_fall++; 00039 } 00040 00041 int main () 00042 { 00043 spi.format(18,3); ////////////////////////////////////// 00044 spi.frequency(100000); // Initialisation SPI software 00045 CS=1; 00046 lcd.cls();///////////////////////////////////////////// 00047 00048 wait_ms(100);/////////////////////////////////////////// 00049 CS=0; 00050 wait_us(50); 00051 00052 pos_initiale=spi.write(0); //Determination pos_initialetion initiale 00053 00054 wait_us(50); 00055 CS=1; 00056 pos_initiale = pos_initiale>>5;///////////////////////////////////////////// 00057 00058 pos_finale=x-pos_initiale; 00059 00060 //pas = (abs(x-x1))%4095; 00061 distance=((pos_finale*(0.000488)+(cpt_rise*2))); 00062 00063 while(1) { 00064 pos_finale=x-pos_initiale; 00065 00066 index.fall(&pressed); 00067 index.rise(&released); 00068 00069 wait_ms(100); 00070 CS=0; 00071 wait_us(50); 00072 00073 x1=x; 00074 x=spi.write(0); 00075 00076 //pas = (abs(x-x1))%4095; 00077 distance=((pos_finale*(0.000488)+(cpt_rise*2))); // Calcul de la distance parcouru depuis le 0 en mm 00078 00079 wait_us(50); 00080 CS=1; 00081 x = x>>5; 00082 00083 lcd.locate(0,3); 00084 lcd.printf("DIST= %.5f",distance); 00085 lcd.locate(0,14); 00086 lcd.printf("POS= %5ld", x); 00087 00088 /* 00089 lcd.locate(0,3); 00090 lcd.printf("pos_initiale= %ld",pos_initiale); 00091 lcd.locate(0,14); 00092 lcd.printf("POS= %5ld", x); 00093 */ 00094 } 00095 }
Generated on Wed Jul 13 2022 07:31:58 by
1.7.2
