![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
test
Fork of HelloWorld by
main.cpp
- Committer:
- kkalsi
- Date:
- 2017-09-01
- Revision:
- 21:74482f23c8fe
- Parent:
- 20:107380f7eeb9
- Child:
- 22:706708bc4c1a
File content as of revision 21:74482f23c8fe:
#include "mbed.h" #include "MMA8452Q.h" Serial pc(USBTX, USBRX); // tx, rx SPI accel(p11,p12,p13); DigitalOut cs(p14); // Communication I2C //I2C comI2C(p9,p10); // sda, scl int main() { // Power up the UART3 it's disabled on powerup. LPC_SC->PCONP |= (1UL << 25); // Setup the PCLK for UART3 // LPC_SC->PCLKSEL1 &= ~(3UL << 18); // Clean LPC_SC->PCLKSEL1 |= (1UL << 18); // PCLK = CCLK // Setup the baud rate for 9600 LPC_UART3->LCR = 0x80; // LPC_UART3->LCR |= (1UL << 7); LPC_UART3->DLM = 0x2; LPC_UART3->DLL = 0x71; LPC_UART3->LCR = 0x3; // 8-bit character length // Enable the pins on the device to use UART3 LPC_PINCON->PINSEL0 |= (3UL << 18); LPC_PINCON->PINSEL0 |= (3UL << 20); // Enable and reset UART3 FIFOs. LPC_UART3->FCR = 0x7; // Enable the interrupt NVIC_EnableIRQ(UART3_IRQn); // Init the UART3 RX interrupt LPC_UART3->IER = 0x01; LPC_UART3->LCR &= ~(1UL << 7); LPC_UART3->THR = 7; /* while(LPC_UART3->THRE = 0) { } */ /* float x, y, z ; MMA8452Q acc(p9,p10,0x1d); // acceleration object while (true) { x = acc.getAccX() ; y = acc.getAccY() ; z = acc.getAccZ() ; printf("X[%.3f] Y[%.3f] Z[%.3f]\n",x, y, z) ; wait(0.1); int X = x * 1000; int Y = y * 1000; int Z = z * 1000; int angle = (1000-(((2*X*X+2*Y*Y)*1000/(X*X+Y*Y+Z*Z)))); pc.printf("avant acos = %d", angle); //float resultat = ((3.14/2.0) -( angle + (angle *angle * angle)/6.0 + (3*angle*angle*angle*angle*angle)/40.0))/2; float angleAcos = angle/1000.0; int resultat = 500*acos((angleAcos)); pc.printf("valeur rad new= %d", resultat); int degree = resultat * 18000/31400; pc.printf("valeur deg new = %d", degree); //degree = degree * 10; int degreInt = degree; pc.printf("valeur deg new = %d", degreInt); int rep; // extracting digits int digits[4] = {0,0,0,0}; int i = 0; while(degreInt > 0) { rep = degreInt % 10; //to get the right most digit digits[i]=rep; pc.printf("digit %d = %d, degree int: %d", i, digits[i], degreInt); degreInt /= 10; //reduce the number by one digit ++i; } cs = 0; accel.write(0x76); // Clear display cs = 1; wait(0.1); cs = 0; accel.write(0x77); // Decimal control command accel.write(0x04);// Turn on decimal cs = 1; wait(0.01); cs = 0; accel.write(digits[3]); cs = 1; wait(0.01); cs = 0; accel.write(digits[2]); cs = 1; wait(0.01); cs = 0; accel.write(digits[1]); cs = 1; wait(0.01); cs = 0; accel.write(digits[0]); cs = 1; wait(0.1); } */ } /* communication SPI Serial pc(USBTX, USBRX); // tx, rx SPI acc(p11,p12,p13); DigitalOut cs(p14); int main() { while(1){ int nombre = 0; pc.printf("Entrez un nombre de 4 chiffres : "); pc.scanf("%d", &nombre); pc.printf("Votre numero entrez est le : %d", nombre); cs = 0; acc.write(nombre); cs = 1; wait(0.2); cs = 0; wait(1); } }*/ /* Serial pc(USBTX, USBRX); // tx, rx Serial mc(p13,p14); int main() { int nombre = 0; pc.printf("Entrez un nombre de 4 chiffres : "); pc.scanf("%d", &nombre); pc.printf("Votre numero entrez est le : %d", nombre); mc.printf(nombre); } */ /* DigitalOut myled(LED2); int main() { while(1) { myled = 1; wait(0.2); myled = 0; wait(0.2); } } */