1. #include <ncurses.h>
  2. #include <unistd.h>
  3.  
  4. #include "adxl345.v5.h"
  5.  
  6. int main(){
  7.     float x = 0;
  8.     float y = 0;
  9.     float z = 0;
  10.  
  11.     int i, x_bar, y_bar, z_bar;
  12.  
  13.     if(accelerometer_init() == 0)
  14.         return 1;
  15.  
  16.     initscr();              /* start the curses mode */
  17.     start_color();
  18.     init_pair(1, COLOR_RED, COLOR_BLACK);
  19.     init_pair(2, COLOR_GREEN, COLOR_BLACK);
  20.  
  21.     while(true){
  22.         get_data_x(&x);
  23.         get_data_y(&y);
  24.         get_data_z(&z);
  25.         clear();
  26.  
  27.             x_bar = x/0.1;
  28.             y_bar = y/0.1;
  29.             z_bar = z/0.1;
  30.  
  31.                 mvprintw(0,0,"X:");
  32.  
  33.         if(x < 0){
  34.             x_bar *= -1;
  35.             attron(COLOR_PAIR(1));
  36.         }else
  37.             attron(COLOR_PAIR(2));
  38.  
  39.         for(i = 0; i <= x_bar; i++)
  40.             mvprintw(0,i+3,"|");
  41.  
  42.         if(x < 0)
  43.                     attroff(COLOR_PAIR(1));
  44.             else
  45.                     attroff(COLOR_PAIR(2));
  46.  
  47.         //Y bars
  48.                 mvprintw(1,0,"Y:");
  49.  
  50.         if(y < 0){
  51.                     y_bar *= -1;
  52.                     attron(COLOR_PAIR(1));
  53.             }else
  54.                     attron(COLOR_PAIR(2));
  55.  
  56.             for(i = 0; i <= y_bar; i++)
  57.                     mvprintw(1,i+3,"|");
  58.  
  59.         if(y < 0)
  60.                     attroff(COLOR_PAIR(1));
  61.             else
  62.                     attroff(COLOR_PAIR(2));
  63.  
  64.         //Z bars
  65.                 mvprintw(2,0,"Z:");
  66.         if(z < 0){
  67.                     z_bar *= -1;
  68.                     attron(COLOR_PAIR(1));
  69.             }else
  70.                     attron(COLOR_PAIR(2));
  71.  
  72.             for(i = 0; i <= z_bar; i++)
  73.                     mvprintw(2,i+3,"|");
  74.         if(z < 0)
  75.                     attroff(COLOR_PAIR(1));
  76.             else
  77.                     attroff(COLOR_PAIR(2));
  78.  
  79. /*
  80.                 mvprintw(3,0,"X: %1.3f",x);
  81.                 mvprintw(4,0,"Y: %1.3f",y);
  82.                 mvprintw(5,0,"Z: %1.3f",z);
  83. */
  84.         //Wait
  85.         refresh();
  86.         usleep (100000) ;
  87.     }
  88.  
  89.     endwin();           /* End curses mode        */
  90.  
  91.     return 0;
  92. }