Question

In: Electrical Engineering

I am working on a project that requires a measurement of acceleration. I have a ADXL345...

I am working on a project that requires a measurement of acceleration. I have a ADXL345 accelerometer, an aduino and a MAX7219 dot matrix display. I need help setting up a code for my aduino to display the acceleration from the ADXL345 accelerometer onto the MAX7219 display. Please help!

Solutions

Expert Solution

connections are as follos

matrix connection

copy the below code it display accelerometer reading of x direction

//Arduino, adxl 345 and Dot Matrix Display
/*********** COMMUNICATION SELECTION ***********/

#include "LedControl.h" //include library for interfacing MAX7219
LedControl lc=LedControl(12,11,10,1);

#include <Wire.h>
#include <FaBo3Axis_ADXL345.h>
FaBo3Axis fabo3axis;


int display;

void setup()
{
Serial.begin(9600);
Serial.println("Checking I2C device...");
  
if(fabo3axis.searchDevice()){
Serial.println("I am ADXL345");
}
Serial.println("Init...");
fabo3axis.configuration();
fabo3axis.powerOn();
}

void loop()
{
int x,y,z,tensplace,hundredsplace,onesplace;  

fabo3axis.readXYZ(&x,&y,&z);
onesplace = x%10;
x=x/10;
tensplace=x%10;
x=x/100;
hundredsplace=x%10; // you can replace x by y to get acceleration along y axis

display=hundredsplace;
call_display();
delay(500);
display=tensplace;
call_display();
delay(500);
display=onesplace;
call_display();
delay(1000);

}

void call_display()
{
if (display==0)
{
rzero();
}
else if (display==1)
{
rone();
}
else if (display==2)
{
rtwo();
}
else if (display==3)
{
rthree();
}
else if (display==4)
{
rfour();
}
else if (display==5)
{
rfive();
}
else if (display==6)
{
rsix();
}
else if (display==7)
{
rseven();
}
else if (display==8)
{
reight();
}
else if (display==9)
{
rnine();
}

}


void rzero()
{
byte zero[8]={B00000000, B00000000, B00000110, B00001001, B00001001, B00001001, B00000110, B00000000};
lc.setRow(0,0, zero[0]);
lc.setRow(0,1, zero[1]);
lc.setRow(0,2, zero[2]);
lc.setRow(0,3, zero[3]);
lc.setRow(0,4, zero[4]);
lc.setRow(0,5, zero[5]);
lc.setRow(0,6, zero[6]);
lc.setRow(0,7, zero[7]);
}

void rone()
{
byte one[8]={B00000000, B00000000, B00000010, B00000110, B00000010, B00000010, B00000111, B00000000};
lc.setRow(0,0, one[0]);
lc.setRow(0,1, one[1]);
lc.setRow(0,2, one[2]);
lc.setRow(0,3, one[3]);
lc.setRow(0,4, one[4]);
lc.setRow(0,5, one[5]);
lc.setRow(0,6, one[6]);
lc.setRow(0,7, one[7]);
}

void rtwo()
{
byte two[8]={B00000000, B00000000, B00000010, B00000101, B00000010, B00000100, B00000111, B00000000};
lc.setRow(0,0, two[0]);
lc.setRow(0,1, two[1]);
lc.setRow(0,2, two[2]);
lc.setRow(0,3, two[3]);
lc.setRow(0,4, two[4]);
lc.setRow(0,5, two[5]);
lc.setRow(0,6, two[6]);
lc.setRow(0,7, two[7]);
}

void rthree()
{
byte three[8]={B00000000, B00000000, B00000110, B00000001, B00000010, B00000001, B00000110, B00000000};
lc.setRow(0,0, three[0]);
lc.setRow(0,1, three[1]);
lc.setRow(0,2, three[2]);
lc.setRow(0,3, three[3]);
lc.setRow(0,4, three[4]);
lc.setRow(0,5, three[5]);
lc.setRow(0,6, three[6]);
lc.setRow(0,7, three[7]);
}

void rfour()
{
byte four[8]={B00000000, B00000000, B00000101, B00000101, B00000111, B00000001, B00000001, B00000000};
lc.setRow(0,0, four[0]);
lc.setRow(0,1, four[1]);
lc.setRow(0,2, four[2]);
lc.setRow(0,3, four[3]);
lc.setRow(0,4, four[4]);
lc.setRow(0,5, four[5]);
lc.setRow(0,6, four[6]);
lc.setRow(0,7, four[7]);
}

void rfive()
{
byte five[8]={B00000000, B00000000, B00000111, B00000100, B00000111, B00000001, B00000111, B00000000};
lc.setRow(0,0, five[0]);
lc.setRow(0,1, five[1]);
lc.setRow(0,2, five[2]);
lc.setRow(0,3, five[3]);
lc.setRow(0,4, five[4]);
lc.setRow(0,5, five[5]);
lc.setRow(0,6, five[6]);
lc.setRow(0,7, five[7]);
}

void rsix()
{
byte six[8]={B00000000, B00000000, B00000100, B00001000, B00001110, B0001010, B00000100, B00000000};
lc.setRow(0,0, six[0]);
lc.setRow(0,1, six[1]);
lc.setRow(0,2, six[2]);
lc.setRow(0,3, six[3]);
lc.setRow(0,4, six[4]);
lc.setRow(0,5, six[5]);
lc.setRow(0,6, six[6]);
lc.setRow(0,7, six[7]);
}

void rseven()
{
byte seven[8]={B00000000, B00000000, B00001111, B00000001, B00000010, B00000100, B00001000, B00000000};
lc.setRow(0,0, seven[0]);
lc.setRow(0,1, seven[1]);
lc.setRow(0,2, seven[2]);
lc.setRow(0,3, seven[3]);
lc.setRow(0,4, seven[4]);
lc.setRow(0,5, seven[5]);
lc.setRow(0,6, seven[6]);
lc.setRow(0,7, seven[7]);
}

void reight()
{
byte eight[8]={B00000000, B00000000, B00000110, B00001001, B00000110, B00001001, B00000110, B00000000};
lc.setRow(0,0, eight[0]);
lc.setRow(0,1, eight[1]);
lc.setRow(0,2, eight[2]);
lc.setRow(0,3, eight[3]);
lc.setRow(0,4, eight[4]);
lc.setRow(0,5, eight[5]);
lc.setRow(0,6, eight[6]);
lc.setRow(0,7, eight[7]);
}

void rnine()
{
byte nine[8]={B00000000, B00000000, B00000100, B00001010, B00001110, B00000010, B00000100, B00000000};
lc.setRow(0,0, nine[0]);
lc.setRow(0,1, nine[1]);
lc.setRow(0,2, nine[2]);
lc.setRow(0,3, nine[3]);
lc.setRow(0,4, nine[4]);
lc.setRow(0,5, nine[5]);
lc.setRow(0,6, nine[6]);
lc.setRow(0,7, nine[7]);
}

void lzero()
{
byte zero[8]={B00000000, B00000000, B01100000, B10010000, B10010000, B10010000, B01100000, B00000000};
lc.setRow(0,0, zero[0]);
lc.setRow(0,1, zero[1]);
lc.setRow(0,2, zero[2]);
lc.setRow(0,3, zero[3]);
lc.setRow(0,4, zero[4]);
lc.setRow(0,5, zero[5]);
lc.setRow(0,6, zero[6]);
lc.setRow(0,7, zero[7]);
}

void lone()
{
byte one[8]={B00000000, B00000000, B00100000, B01100000, B00100000, B00100000, B01110000, B00000000};
lc.setRow(0,0, one[0]);
lc.setRow(0,1, one[1]);
lc.setRow(0,2, one[2]);
lc.setRow(0,3, one[3]);
lc.setRow(0,4, one[4]);
lc.setRow(0,5, one[5]);
lc.setRow(0,6, one[6]);
lc.setRow(0,7, one[7]);
}

void ltwo()
{
byte two[8]={B00000000, B00000000, B00100000, B01010000, B00100000, B01000000, B01110000, B00000000};
lc.setRow(0,0, two[0]);
lc.setRow(0,1, two[1]);
lc.setRow(0,2, two[2]);
lc.setRow(0,3, two[3]);
lc.setRow(0,4, two[4]);
lc.setRow(0,5, two[5]);
lc.setRow(0,6, two[6]);
lc.setRow(0,7, two[7]);
}

void lthree()
{
byte three[8]={B00000000, B00000000, B01100000, B00010000, B00100000, B00010000, B01100000, B00000000};
lc.setRow(0,0, three[0]);
lc.setRow(0,1, three[1]);
lc.setRow(0,2, three[2]);
lc.setRow(0,3, three[3]);
lc.setRow(0,4, three[4]);
lc.setRow(0,5, three[5]);
lc.setRow(0,6, three[6]);
lc.setRow(0,7, three[7]);
}

void lfour()
{
byte four[8]={B00000000, B00000000, B01010000, B01010000, B01110000, B00010000, B00010000, B00000000};
lc.setRow(0,0, four[0]);
lc.setRow(0,1, four[1]);
lc.setRow(0,2, four[2]);
lc.setRow(0,3, four[3]);
lc.setRow(0,4, four[4]);
lc.setRow(0,5, four[5]);
lc.setRow(0,6, four[6]);
lc.setRow(0,7, four[7]);
}

void lfive()
{
byte five[8]={B00000000, B00000000, B01110000, B01000000, B01110000, B00010000, B01110000, B00000000};
lc.setRow(0,0, five[0]);
lc.setRow(0,1, five[1]);
lc.setRow(0,2, five[2]);
lc.setRow(0,3, five[3]);
lc.setRow(0,4, five[4]);
lc.setRow(0,5, five[5]);
lc.setRow(0,6, five[6]);
lc.setRow(0,7, five[7]);
}

void lsix()
{
byte six[8]={B00000000, B00000000, B01000000, B10000000, B11100000, B10100000, B01000000, B00000000};
lc.setRow(0,0, six[0]);
lc.setRow(0,1, six[1]);
lc.setRow(0,2, six[2]);
lc.setRow(0,3, six[3]);
lc.setRow(0,4, six[4]);
lc.setRow(0,5, six[5]);
lc.setRow(0,6, six[6]);
lc.setRow(0,7, six[7]);
}

void lseven()
{
byte seven[8]={B00000000, B00000000, B11110000, B00010000, B00100000, B01000000, B10000000, B00000000};
lc.setRow(0,0, seven[0]);
lc.setRow(0,1, seven[1]);
lc.setRow(0,2, seven[2]);
lc.setRow(0,3, seven[3]);
lc.setRow(0,4, seven[4]);
lc.setRow(0,5, seven[5]);
lc.setRow(0,6, seven[6]);
lc.setRow(0,7, seven[7]);
}

void leight()
{
byte eight[8]={B00000000, B00000000, B01100000, B10010000, B01100000, B10010000, B01100000, B00000000};
lc.setRow(0,0, eight[0]);
lc.setRow(0,1, eight[1]);
lc.setRow(0,2, eight[2]);
lc.setRow(0,3, eight[3]);
lc.setRow(0,4, eight[4]);
lc.setRow(0,5, eight[5]);
lc.setRow(0,6, eight[6]);
lc.setRow(0,7, eight[7]);
}

void lnine()
{
byte nine[8]={B00000000, B00000000, B01000000, B10100000, B11100000, B00100000, B01000000, B00000000};
lc.setRow(0,0, nine[0]);
lc.setRow(0,1, nine[1]);
lc.setRow(0,2, nine[2]);
lc.setRow(0,3, nine[3]);
lc.setRow(0,4, nine[4]);
lc.setRow(0,5, nine[5]);
lc.setRow(0,6, nine[6]);
lc.setRow(0,7, nine[7]);
}


Related Solutions

I am working on a project where I have to create my own organization (stem cell...
I am working on a project where I have to create my own organization (stem cell research) I need to go further in depth about the program or organization in terms of describing the program implementation and the project evaluation...
I'm working in Java and am working on a project where I need to find an...
I'm working in Java and am working on a project where I need to find an average. The catch is that for some of the values there is no data because they will be entered at a later date. I have variables assigned so that for each entry if there is an input I'll have it say _____available = 1, otherwise the variable will equal 0. I'll use an example to make this more clear. Let's say I am trying...
Attached is the problem I am working on I have to use phantoms, and i have...
Attached is the problem I am working on I have to use phantoms, and i have already completed steps p and H, I need help help with step A , which is to "state and check the assumptions for the hypothesis test", I think the correct hypothesis test to use would be the 2 sample t test, but im not sure. The number of cell phones per 100 residents in countries in Europe is given in table #9.3.9 for the...
I am trying to solve this question: "You are working on a school project at the...
I am trying to solve this question: "You are working on a school project at the library when your friend Jane taps you on the shoulder. She cannot seem to connect to a certain website that she needs for her class. Fortunately, you know enough about Windows and networking to help troubleshoot the problem. You open a Windows command prompt and ......" The dots at the end of the story indicates that I need to continue the story. However, I...
Here is a project I am currently working on and I could use some feedback on...
Here is a project I am currently working on and I could use some feedback on how to get started. I calculated the general probabilities for the first two columns of each spreadsheet (successes / total outcomes). I don't want to move forward until I know I'm on the right track but I'm concerned that I've oversimplified the question being asked. I'm also using Excel and am having a hard time finding an appropriate formula for conditional probability. My book...
i am working on a project.. i would love to implement ENERGY METERING WITH IT SO...
i am working on a project.. i would love to implement ENERGY METERING WITH IT SO AS TO BE ABLE TO CALCULATE THE BILLS AT THE END OF A CERTAIN PERIOD.. how could this be done...BULBS,FANS,SOCKETS are the appliances involved... how can i get the energy used by all this appliances. i need very DETAILED TECHNICAL EXPLANATION.
I am making a working reagent that requires a 50:1 ratio (50 of reagent A and...
I am making a working reagent that requires a 50:1 ratio (50 of reagent A and 1 of reagent B) and a total volume of 600uL. Therefore, I need 588uL of reagent A (water) and 12uL of reagent B (lead acetate). I need to make a solution of lead acetate (reagentB) with: 3mM,7.7mM, and 46mM. Upon calculating the mass needed to make 3mM, 7.7mM, and 46mM I got: 0.9756 mg, 2.504 mg, and 14.9592 mg respectively and to each mass...
I am working on an Arduino Project. I would like to build a controllable RGB LED...
I am working on an Arduino Project. I would like to build a controllable RGB LED Nightlight (with a debounce code included). With each time pushing the button I want a different color. like the following Initial state = LED off first press= LED turns on Red second Press = LED turns on Green third Press = LED turns on Blue Fourth Press = LED turns on Purple Fifth Press = LED turns on Teal sixth press= LED turns on...
I am working on an accounting project related to a supermarket and would like to seek...
I am working on an accounting project related to a supermarket and would like to seek help with regard to its costing system. I was asked to describe the company’s costing system. I have identified supermarket as a value-added intermediary between suppliers and customers, but how do I classify or describe it's costing system since it does not manufacture its own product. Would there be a manufacturing cost incurred or I can only trace non-manufacturing costs to its products? I...
1. I am trying to determine the level of measurement of my data type? I am...
1. I am trying to determine the level of measurement of my data type? I am looking for advice on Nominal, Ordinal, Interval, and Ratio 2. Does the data set have any categorical variables? I am trying to Describe the data set below in very general terms? This data consist of 8 variables: Which are GRE Scores, TOEFL Scores, University Rating, Statement of Purpose, Letter of Recommendation Strength, Undergraduate GPA, . Research Experience, and Chance of Admit. Name Type Description...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT