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 #include "mbed.h" 00002 Serial pc(USBTX, USBRX); // tx, rx 00003 DigitalOut led1(LED1); 00004 DigitalOut led2(LED2); 00005 DigitalOut led3(LED3); 00006 DigitalIn butt = (USER_BUTTON); 00007 00008 DigitalOut CLK(PA_3); 00009 DigitalIn DATA(PD_7); 00010 00011 int readSSI(DigitalOut CLK, DigitalIn DATA){ 00012 int i,tmp,numBits = 13; 00013 int angle = 0b00000000000000; //Initialise 13 bit 0 binary 00014 CLK=1; //Bring CLK high 00015 for(i =0;i<numBits;i++){ 00016 CLK = 0; 00017 wait_us(10); 00018 CLK =1; 00019 wait_us(10); //CLK cycle 00020 tmp = DATA.read(); 00021 angle = angle<<1; //Shift previous read bits 00022 angle += tmp; //Add new bit 00023 } 00024 wait_us(16); //Timeout 16us from datasheet 00025 CLK =0; 00026 return angle; 00027 } 00028 00029 00030 int angle; 00031 00032 int main() { 00033 while(butt == 0){ //Startup readings 00034 led1 =!led1; 00035 led2=!led2; 00036 led3=!led3; 00037 wait(0.1f); 00038 } 00039 wait(0.5f); 00040 printf("\r\n Start"); 00041 00042 while(1){ 00043 printf("\r\n"); 00044 CLK =0; 00045 angle = readSSI(CLK, DATA); 00046 printf("\r\n%d\r\n",angle); 00047 wait(.5f); 00048 } 00049 } 00050 00051
Generated on Wed Jul 20 2022 04:54:04 by
1.7.2