test

Dependencies:   mbed MMA8452Q

Fork of HelloWorld by Simon Ford

Committer:
kkalsi
Date:
Wed Aug 30 19:58:18 2017 +0000
Revision:
7:32229ffff57e
Parent:
6:62e39c103d12
Child:
8:bb27936d2358
retest

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kkalsi 6:62e39c103d12 1 #include "mbed.h"
kkalsi 7:32229ffff57e 2
kkalsi 6:62e39c103d12 3
vincentlabbe 4:a38ef4c242ef 4 //hello
kkalsi 2:42408ce8f4ae 5 Serial pc(USBTX, USBRX); // tx, rx
kkalsi 5:01729ebe170e 6 I2C comI2C(p9,p10); // sda, scl
kkalsi 3:8494c3f7108d 7 // Communication I2C
kkalsi 3:8494c3f7108d 8 int main() {
kkalsi 6:62e39c103d12 9
kkalsi 7:32229ffff57e 10 comI2C.start();
kkalsi 7:32229ffff57e 11 comI2C.write(0x3A); // A write to device 0x1D
kkalsi 7:32229ffff57e 12 comI2C.write(0x06); // Register to read from (acceleration in X)
kkalsi 7:32229ffff57e 13 comI2C.start(); // Need to send start condition here
kkalsi 7:32229ffff57e 14 comI2C.write(0x3B); // Read from device 0x1D
kkalsi 7:32229ffff57e 15 int c=comI2C.read(0); // Read the data with NACK
kkalsi 7:32229ffff57e 16 comI2C.stop();
kkalsi 7:32229ffff57e 17 pc.printf("degree : %d", c);
kkalsi 3:8494c3f7108d 18 }
kkalsi 3:8494c3f7108d 19
kkalsi 3:8494c3f7108d 20
kkalsi 3:8494c3f7108d 21 /* communication SPI
kkalsi 3:8494c3f7108d 22 Serial pc(USBTX, USBRX); // tx, rx
kkalsi 2:42408ce8f4ae 23 SPI acc(p11,p12,p13);
kkalsi 2:42408ce8f4ae 24 DigitalOut cs(p14);
kkalsi 2:42408ce8f4ae 25 int main() {
kkalsi 2:42408ce8f4ae 26 while(1){
kkalsi 2:42408ce8f4ae 27 int nombre = 0;
kkalsi 2:42408ce8f4ae 28 pc.printf("Entrez un nombre de 4 chiffres : ");
kkalsi 2:42408ce8f4ae 29 pc.scanf("%d", &nombre);
kkalsi 2:42408ce8f4ae 30 pc.printf("Votre numero entrez est le : %d", nombre);
kkalsi 2:42408ce8f4ae 31
kkalsi 2:42408ce8f4ae 32 cs = 0;
kkalsi 3:8494c3f7108d 33 acc.write(nombre);
kkalsi 2:42408ce8f4ae 34 cs = 1;
kkalsi 2:42408ce8f4ae 35 wait(0.2);
kkalsi 2:42408ce8f4ae 36 cs = 0;
kkalsi 2:42408ce8f4ae 37 wait(1);
kkalsi 2:42408ce8f4ae 38 }
kkalsi 3:8494c3f7108d 39 }*/
kkalsi 2:42408ce8f4ae 40 /*
kkalsi 2:42408ce8f4ae 41 Serial pc(USBTX, USBRX); // tx, rx
kkalsi 2:42408ce8f4ae 42 Serial mc(p13,p14);
kkalsi 2:42408ce8f4ae 43 int main() {
kkalsi 2:42408ce8f4ae 44
kkalsi 2:42408ce8f4ae 45 int nombre = 0;
kkalsi 2:42408ce8f4ae 46 pc.printf("Entrez un nombre de 4 chiffres : ");
kkalsi 2:42408ce8f4ae 47 pc.scanf("%d", &nombre);
kkalsi 2:42408ce8f4ae 48 pc.printf("Votre numero entrez est le : %d", nombre);
kkalsi 2:42408ce8f4ae 49 mc.printf(nombre);
kkalsi 2:42408ce8f4ae 50 }
kkalsi 2:42408ce8f4ae 51 */
simon 0:fb6bbc10ffa0 52
kkalsi 2:42408ce8f4ae 53
kkalsi 2:42408ce8f4ae 54 /*
kkalsi 2:42408ce8f4ae 55 DigitalOut myled(LED2);
simon 0:fb6bbc10ffa0 56
simon 0:fb6bbc10ffa0 57 int main() {
simon 0:fb6bbc10ffa0 58 while(1) {
simon 0:fb6bbc10ffa0 59 myled = 1;
simon 0:fb6bbc10ffa0 60 wait(0.2);
simon 0:fb6bbc10ffa0 61 myled = 0;
simon 0:fb6bbc10ffa0 62 wait(0.2);
simon 0:fb6bbc10ffa0 63 }
simon 0:fb6bbc10ffa0 64 }
kkalsi 2:42408ce8f4ae 65 */