Programming  >  CODING SOLUTION  >  ECE-GY 6483 Midterm 2 Submission | New York University. UPDATED (All)

ECE-GY 6483 Midterm 2 Submission | New York University. UPDATED

Document Content and Description Below

Midterm 2 Submission Part 1: a) ASensor.h header file: b) ASensor.c file: #ifndef ASENSOR_H #define ASENSOR_H #include <mbed.h> #define SENSOR_ADDRESS 0x74 //7-bit address 1110100 int GetVersi ... on(I2C i2c); int GetTotalStrength(I2C i2c); int GetEvents(I2C i2c); #endif #include <mbed.h> #include “ASensor.h” const int addr8bit = SENSOR_ADDRESS << 1; // NOTE: unsigned char casting is used in the following functions because if the first bit of any of the registers is 1, it might be interpreted as a negative number and sign extended even though the bit manipulations used don’t edit any of the upper 16 bits of the returned int. int GetVersion(I2C i2c) { char cmd[2] = {0x00, 0x04}; // address for major version char stop[3] = {0xEE, 0xEE, 0x00}; // address of register to stop I2C with some data i2c.write(addr8bit, cmd, 2, true); // write register without stop bit i2c.read(addr8bit, cmd, 2); // repeated start to read i2c.write(addr8bit, stop, 3); // manually stopping I2C as per the datasheet // returns major and minor version separated by zeros. If major version was 239 and minor version was 173, the value returned would be 239000173 return (unsigned char)cmd[0]*1000000 + (unsigned char)cmd[1]; } int GetTotalStrength(I2C i2c) { char cmd[2] = {0x00, 0x1A}; // address for touch strength char stop[3] = {0xEE, 0xEE, 0x00}; // address of register to stop I2C with some data i2c.write(addr8bit, cmd, 2, true); // send register without stop bit i2c.read(addr8bit, cmd, 2); // repeated start to read i2c.write(addr8bit, stop, 3); // manually stopping I2C as per the datasheet // returns 32-bit int where the lowest 16 bits are cmd[0] and cmd[1] respectively return ((unsigned char)cmd[0] << 8) | (unsigned char)cmd[1]; } T -UPDATEDpdf/c & d) Main.cpp file: Part 2: int GetEvent(I2C i2c) { char cmd[2] = {0x00, 0x1A}; // address for event gesture 0 char stop[3] = {0xEE, 0xEE, 0x00}; // address of register to stop I2C with some data i2c.write(addr8bit, cmd, 2, true); // send register without stop pit i2c.read(addr8bit, cmd, 2); // repeated start to read i2c.write(addr8bit, stop, 3); // manually stopping I2C as per the datasheet // check if the lower 5 bits of “Gesture Events 0” are all zero and that // the lower 3 bits of “Gesture Events 1” are also all zero if ((cmd[0] | 0xC0 == 0xC0) && (cmd[1] | 0xF8 == 0xF8)) return 0; // returns 32-bit int where the lowest 16 bits are cmd[0] (Gesture Events 0) and cmd[1] (Gesture Events 1) respectively else return ((unsigned char)cmd[0] << 8) | (unsigned char)cmd[1]; } #include <mbed.h> #include “ASensor.h” int main() { I2C i2c(I2C_SDA, I2C_SCL); while(1) { printf(“Event: %d”, GetEvent(i2c)); wait_us(500000); // wait 0.5 seconds [Show More]

Last updated: 1 year ago

Preview 1 out of 5 pages

Buy Now

Instant download

We Accept:

Payment methods accepted on Scholarfriends (We Accept)
Preview image of ECE-GY 6483 Midterm 2 Submission | New York University.  UPDATED document

Buy this document to get the full access instantly

Instant Download Access after purchase

Buy Now

Instant download

We Accept:

Payment methods accepted on Scholarfriends (We Accept)

Reviews( 0 )

$8.00

Buy Now

We Accept:

Payment methods accepted on Scholarfriends (We Accept)

Instant download

Can't find what you want? Try our AI powered Search

133
0

Document information


Connected school, study & course


About the document


Uploaded On

Apr 29, 2023

Number of pages

5

Written in

All

Seller


Profile illustration for PAPERS UNLIMITED™
PAPERS UNLIMITED™

Member since 4 years

509 Documents Sold

Reviews Received
55
20
8
2
8
Additional information

This document has been written for:

Uploaded

Apr 29, 2023

Downloads

 0

Views

 133

More From PAPERS UNLIMITED™

View all PAPERS UNLIMITED™'s documents »

Recommended For You

Get more on CODING SOLUTION »

$8.00
What is Scholarfriends

Scholarfriends.com Online Platform by Browsegrades Inc. 651N South Broad St, Middletown DE. United States.

We are here to help

We're available through e-mail, Twitter, Facebook, and live chat.
 FAQ
 Questions? Leave a message!

Follow us on
 Twitter

Copyright © Scholarfriends · High quality services·