Question

In: Electrical Engineering

You have a plan to build a games console controller that captures the hand gestures of...

You have a plan to build a games console controller that captures the hand gestures of the player. The player’s movements and gestures are sensed using an accelerometer connected to one of the ADC pins of an Arduino. You have already written all the necessary code but have yet to include any kind of smoothing for the accelerometer signal.

Your task now is to write the accelerometer smoothing function. The function must take each new sample as input and return the average of 4 consecutive samples without introducing a significant lag. (Hint: use a moving average.)

Write an implementation of this function where the function prototype is of the form:

int SmoothSensor(int sensorReading);

Solutions

Expert Solution

I modified the code, to implement moving average in the form of function. Given below is the complete code, I have verified this code

const int numReadings = 4;

int readings[numReadings];      // for readings from the analog input
int readIndex = 0;              // it is the index of the current reading
int total = 0;                  // the running total of moving average
int average = 0;                // initial value of the average

int inputPin = A0; // sensor is attached to pin A0

void setup() {
// initialize serial communication with computer:
Serial.begin(9600);
// initialize all the readings to 0:
for (int thisReading = 0; thisReading < numReadings; thisReading++) {
    readings[thisReading] = 0;
}
}

void loop() {
SmoothSensor ();
delay(1);        // delay in between reads for stability
}

int SmoothSensor (){

   // subtract the last reading:
total = total - readings[readIndex];
// read from the sensor:
readings[readIndex] = analogRead(inputPin);
// add the reading to the total:
total = total + readings[readIndex];
// advance to the next position in the array:
readIndex = readIndex + 1;

// if we're at the end of the array...
if (readIndex >= numReadings) {
    // ...wrap around to the beginning:
    readIndex = 0;
}

// calculate the average:
average = total / numReadings;
// send it to the computer as ASCII digits
Serial.println(average);
}


Related Solutions

In repeated games, players do not have the opportunity to build a reputation and to discover...
In repeated games, players do not have the opportunity to build a reputation and to discover more about the opponent. True False
In the game console industry, game developers sell their games separately or along with the game...
In the game console industry, game developers sell their games separately or along with the game console producers. Which of the following best describe the role of game developers for game console producers? -Substitutes because game developers appropriate value from the sales of game consoles. -Partners because game developers need to customize their games to game consoles. -Complementors because games enhance the value of the game consoles. -Suppliers because game developers provide games for game consoles.
Identify three games that you have played that contain an economic concept that you have learned...
Identify three games that you have played that contain an economic concept that you have learned about this semester. You can choose board games, video games, sports, etc... but do NOT choose Monopoly (be creative). For each game write a paragraph that describes how the game incorporates the economic concept you identified (you should have different economic concept for each game).
You have $20,000. After the “success” of the sequel of the “Hunger Games”, you want to...
You have $20,000. After the “success” of the sequel of the “Hunger Games”, you want to know if Lions Gate Entertainment Corp. (NYSE:LGE) is a good buy. The firm’s total risk is 19%, its systematic risk is 0.57, the t-bill rate is 2.0%, the 30 year treasury rate is 3.5%, and the average market return is 8.8%. What is the expected return on Lions Gate Entertainment Corp? Assume you constructed a DCF model to evaluate Lions Gate Entertainment Corp and...
you bought some land for $1,200,000 your plan is to build an apartment building for $1,300,000...
you bought some land for $1,200,000 your plan is to build an apartment building for $1,300,000 which will provide you with rental revenue of $500,000 per year depreciation is straight line with a 30 year life and no salvage The tax rate is 34% an ordinary income and 20% on capital gains what will you need to sell the apartment for before taxes in 15 years to earn a 15% after tax return?
1. You plan to build a toy house with a tiny light bulb inside that can...
1. You plan to build a toy house with a tiny light bulb inside that can be lit with 1 amp of current, for your little brother to entertain him! You have two D-size (1.5 V each) batteries and two 6-ohm resistors. How can you arrange the resistors to get the desired current? A) resistors should be connected in parallel to each other and this combination in series with batteries B) resistors may be connected in series with each other...
when you build cafe what is your marketing plan and how sales are to be made...
when you build cafe what is your marketing plan and how sales are to be made ?
You are playing blackjack at a casino and have a hand with a total of 19....
You are playing blackjack at a casino and have a hand with a total of 19. You decide to stay. The dealer flips over their facedown card to reveal a total of 16. What is the probability that you win? Assume you are playing with an infinite deck. A.8/13 B.9/13 C.10/13 D.11/13
13. You have just turned 50 and you plan to save for retirement. You plan to...
13. You have just turned 50 and you plan to save for retirement. You plan to retire in 12 years. Once you retire you would like to have an income of $50,000 per year for the next 12 years. Determine the amount you must deposit at the beginning of each year to finance your retirement income. Use the following assumptions to determine this annual deposit: a. All savings compound at a rate of 5% per year. b. You make the...
The bystander effect captures a shadowy side of human nature. It may have contributed to atrocities...
The bystander effect captures a shadowy side of human nature. It may have contributed to atrocities such as the Holocaust and witch hunts. It may have its roots in childhood with those who watch bullying without intervening. Discuss the bystander effect utilizing the links below or recent news stories. Include in your discussion: One factor that might increase the chances of helping another One factor that might decrease the likelihood that a person in need will receive help. Note that...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT