h

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
nemanja1994
Date:
Wed Jun 27 22:46:17 2018 +0000
Commit message:
gh;

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 6dd0e83d5378 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Jun 27 22:46:17 2018 +0000
@@ -0,0 +1,145 @@
+#include "mbed.h"
+const int addr = 0x74<<1;
+Serial pc(USBTX,USBRX);
+I2C i2c(D14, D15);
+//AnalogIn rpm(A0);
+int RPM;
+char cmd[3];
+DigitalOut reset(D2);
+void initialize(){
+    reset.write(1);
+    // set port as output
+    cmd[0]=0x06;
+    cmd[1]=0x00;
+    cmd[2]=0x00;
+    i2c.write(addr,cmd,3);
+}
+void showLedRpm(int RPM){
+    if(RPM<1000) {
+        cmd[1]=0xFF;
+        cmd[2]=0xFF;
+        }
+    else if (RPM<2000) {
+        cmd[1]=0xFF;
+        cmd[2]=0xDF;
+        }
+    else if (RPM <3000) {
+        cmd[1]=0xFF;
+        cmd[2]=0xCF;
+        }
+    else if (RPM <4000) {
+        cmd[1]=0xFF;
+        cmd[2]=0xC7;
+        }
+    else if (RPM <5000) {
+        cmd[1]=0xFF;
+        cmd[2]=0xC3;
+        }
+    else if (RPM <6000) {
+        cmd[1]=0xFF;
+        cmd[2]=0xC1;
+        }
+    else if (RPM <7000) {
+        cmd[1]=0xFF;
+        cmd[2]=0xC0;
+        }
+    else if (RPM <8000) {
+        cmd[1]=0xBF;
+        cmd[2]=0xC0;
+        }
+    else if (RPM <9000) {
+        cmd[1]=0x9F;
+        cmd[2]=0xC0;
+        }
+    else if (RPM <10000) {
+        cmd[1]=0x8F;
+        cmd[2]=0xC0;
+        }
+    else if (RPM <11000) {
+        cmd[1]=0x87;
+        cmd[2]=0xC0;
+        }
+    else if (RPM <12000) {
+        cmd[1]=0x83;
+        cmd[2]=0xC0;
+        }
+    else if (RPM <13000) {
+        cmd[1]=0x81;
+        cmd[2]=0xC0;
+        }
+    else {
+        cmd[1]=0x80;
+        cmd[2]=0xC0;
+        }
+    cmd[0]=0x02;
+    i2c.write(addr, cmd, 3);
+}
+
+int main() {  
+    initialize();
+    while(1){
+        
+        for(RPM=0;RPM<=13000;RPM=RPM+100){
+            showLedRpm(RPM);
+            pc.printf("%d\n",RPM);
+        };
+        
+        // this is led blinking, make this as a function 
+        cmd[0]=0x02;
+        cmd[1]=0xFF;
+        cmd[2]=0xFF;
+        i2c.write(addr,cmd,3);
+        wait(0.1);
+        cmd[0]=0x02;
+        cmd[1]=0x00;
+        cmd[2]=0x00;
+        i2c.write(addr,cmd,3);
+        wait(0.1);
+        cmd[0]=0x02;
+        cmd[1]=0xFF;
+        cmd[2]=0xFF;
+        i2c.write(addr,cmd,3);
+        wait(0.1);
+        cmd[0]=0x02;
+        cmd[1]=0x00;
+        cmd[2]=0x00;
+        i2c.write(addr,cmd,3);
+        wait(0.1);
+        cmd[0]=0x02;
+        cmd[1]=0xFF;
+        cmd[2]=0xFF;
+        i2c.write(addr,cmd,3);
+        wait(0.1);
+        cmd[0]=0x02;
+        cmd[1]=0x00;
+        cmd[2]=0x00;
+        i2c.write(addr,cmd,3);
+        wait(0.1);
+        cmd[0]=0x02;
+        cmd[1]=0xFF;
+        cmd[2]=0xFF;
+        i2c.write(addr,cmd,3);
+        wait(0.1);
+        cmd[0]=0x02;
+        cmd[1]=0x00;
+        cmd[2]=0x00;
+        i2c.write(addr,cmd,3);
+        wait(0.1);
+        cmd[0]=0x02;
+        cmd[1]=0xFF;
+        cmd[2]=0xFF;
+        i2c.write(addr,cmd,3);
+        wait(0.1);
+        cmd[0]=0x02;
+        cmd[1]=0x00;
+        cmd[2]=0x00;
+        i2c.write(addr,cmd,3);
+        wait(0.1);
+        cmd[0]=0x02;
+        cmd[1]=0xFF;
+        cmd[2]=0xFF;
+        i2c.write(addr,cmd,3);
+        wait(3);
+    };
+};
+
diff -r 000000000000 -r 6dd0e83d5378 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Jun 27 22:46:17 2018 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/a7c7b631e539
\ No newline at end of file