Go Down

Topic: interrupt and wire library. (Read 580 times) previous topic - next topic


Im writing a program thats basically a g force meter.  so to make it more accurate i need to check the accelerometer about every 10-20 ms.  so i decided to try a timer interrupt.  when it enters the function it hangs on the chuck.update() command.  
excuse the code.  

im just trying to get a proof of concept.  

Code: [Select]
#include <math.h>
#include "Wire.h"
#include "WiiChuck.h"
#include "TimerOne.h"

WiiChuck chuck = WiiChuck();

float velocity =0;
float velocity_mph =0;
float velocity_acc =0;
float staccel =0;
float lataccel =0;
float gx=0;
float gy =0;

int pitch=0;
int roll=0;
int count=0;
long previous =0;

void setup(){
// Timer1.attachInterrupt(callback);

int num =1;
void callback(){
void help(){
 else num=1;

void loop(){
if(millis()-previous >200){
   previous = millis();
void Print(){
 Serial.print(" ST:");
 Serial.print(" ");
 Serial.print(" ");
 Serial.print(" ");

void get_data(){


 velocity_acc = (staccel/50)*9.81;
 velocity = velocity + velocity_acc;
 velocity_mph = velocity * 2.23693629;
 if(count> 5){
 count = 0;
 gx =  staccel / 5;
 gy = lataccel / 5;
 staccel =0;



void selectLineOne(){  //puts the cursor at line 0 char 0.
  Serial.print(0xFE, BYTE);   //command flag
  Serial.print(128, BYTE);    //position
void selectLineTwo(){  //puts the cursor at line 0 char 0.
  Serial.print(0xFE, BYTE);   //command flag
  Serial.print(192, BYTE);    //position
void clearLCD(){
  Serial.print(0xFE, BYTE);   //command flag
  Serial.print(0x01, BYTE);   //clear command.
void backlightOn(){  //turns on the backlight
     Serial.print(0x7C, BYTE);   //command flag for backlight stuff
     Serial.print(157, BYTE);    //light level.
void backlightOff(){  //turns off the backlight
     Serial.print(0x7C, BYTE);   //command flag for backlight stuff
     Serial.print(128, BYTE);     //light level for off.
void serCommand(){   //a general function to call the command flag for issuing all other commands  
     Serial.print(0xFE, BYTE);
void backlight(int val){  //turns on the backlight
     val=val+128;                 // turn it to amounts understood by lcd
     Serial.print(0x7C, BYTE);   //command flag for backlight stuff
     Serial.print(val, BYTE);    //light level.
void selectcursor(int val1, int val2){    // val1 = line val2 = position
     int val= 128+val2+64*val1;
     Serial.print(0xFE, BYTE);   //command flag
  Serial.print(val, BYTE);    //position
void printDouble( double val, unsigned int precision){
     // prints val with number of decimal places determine by precision
     // NOTE: precision is 1 followed by the number of zeros for the desired number of decimial places
     // example: printDouble( 3.1415, 100); // prints 3.14 (two decimal places)
     Serial.print (int(val));  //prints the int part
     Serial.print("."); // print the decimal point
     unsigned int frac;
     if(val >= 0)
           frac = (val - int(val)) * precision;
           frac = (int(val)- val ) * precision;
     if(frac <100)Serial.print(0);
     if(frac <10)Serial.print(0);
     Serial.print(frac,DEC) ;

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131