Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write C code that senses 3 accelerometer readings into pins PAD 8, 9 and 10 and

ID: 2989228 • Letter: W

Question

Write C code that senses 3 accelerometer readings into pins PAD 8, 9 and 10 and displays them on the LCD. Also run a timer in seconds and log the values of the accelerometers in 3 arrays every second. (Using Dragon board 12)

Explanation / Answer

char commandLetter; // the delineator / command chooser char numStr[4]; // the number characters and null long speed; // the number stored as a long integer void serialEvent() { // Parse the string input once enough characters are available if(Serial.available() >= 4) { commandLetter = Serial.read(); //dump the buffer if the first character was not a letter if ( ! isalpha( commandLetter ) { // dump until a letter is found or nothing remains while(( ! isalpha( Serial.peak() ) && Serial.available()) { Serial.read(); // throw out the letter } //not enough letters left, quit if ( Serial.available() < 3 ) { return; } } // read the characters from the buffer into a character array for( int i = 0; i < 3; ++i ) { numStr[i] = Serial.read(); } //terminate the string with a null prevents atol reading too far numStr[i] = ''; //read character array until non-number, convert to long int speed = atol(numStr); Serial.println(speed); } } void i2cSend(float numberToPrint) { int decimalPlace = -1; //find decimal place, fix the position of leftmost digit to the left if ( numberToPrint < 0 ) { i2cSend( int( numberToPrint * 100 ) ); decimalPlace = DECIMAL1; } else if ( numberToPrint < 10 ) { i2cSend( int( numberToPrint * 1000 ) ); decimalPlace = DECIMAL1; } else if ( numberToPrint < 100 ) { i2cSend( int( numberToPrint * 100) ); decimalPlace = DECIMAL2; } else if ( numberToPrint < 1000 ) { i2cSend( int( numberToPrint * 10) ); decimalPlace = DECIMAL3; } else { i2cSend( numberToPrint ); } if ( decimalPlace != -1 ) { Wire.beginTransmission(DISPLAY_ADDRESS1); // transmit to device #1 Wire.write( 0x77 ); // send decimal command Wire.write( 1
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote