hi could some one help me out with this code it is supposed to show y axis on 1 bar led and x axis on bar 2 led
in the serial monitor it shows correct measures and that it is working but on the led output it seams to cross paths and use the y axis on both graphs
thanks for looking it driving me mad lol
#include <AcceleroMMA7361.h>
AcceleroMMA7361 accelero;
int x;
int y;
const int ledCount = 9; // the number of LEDs in the bar graph
const int buttonPin = 2; // the number of the pushbutton pin
int ledPins[] = {
24, 26, 28, 30, 32, 34, 36, 38, 40 }; // an array of pin numbers to which LEDs are attached
int ledPins2[] = {
44, 45, 46, 47, 48, 49, 50, 51, 52 }; // an array of pin numbers to which LEDs are attached
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
void setup()
{
Serial.begin(9600);
accelero.begin(13, 12, 11, 10, A0, A1, A2);
accelero.setARefVoltage(3.3); //sets the AREF voltage to 3.3V
accelero.setSensitivity(LOW); //sets the sensitivity to +/-6G
{
// loop over the pin array and set them all to output:
for (int thisLed = 0; thisLed < ledCount; thisLed++)
pinMode(ledPins[thisLed], OUTPUT);}
{
for (int thisLed2 = 0; thisLed2 < ledCount; thisLed2++)
pinMode(ledPins2[thisLed2], OUTPUT);}
{
pinMode(buttonPin, INPUT);
}
}
void loop()
{
x = accelero.getXVolt();
y = accelero.getYVolt();
Serial.print("\nx: Forward + Back Reading = ");
Serial.print(x);
Serial.print("\ty: Left + Right Reading = ");
Serial.print(y);
Serial.print("");
{
{
// clear all the LEDs
for (int thisLed = 0; thisLed < ledCount; thisLed++)
digitalWrite(ledPins[thisLed], LOW);
int bar1 = map(y, 1500, 1970, 0, 10);
int bar = constrain(bar1, 0, 10);
Serial.print(" bar reading = ");
Serial.println(bar); // the raw analog reading
for (int thisLed = bar; thisLed < bar+3; thisLed++)
digitalWrite(ledPins[thisLed], HIGH);
}
{
for (int thisLed2 = 0; thisLed2 < ledCount; thisLed2++)
digitalWrite(ledPins2[thisLed2], LOW);
int bar12 = map(x, 1500, 1805, 0, 10);
int bar2 = constrain(bar12, 0, 10);
Serial.print(" bar2 reading = ");
Serial.println(bar2); // the raw analog reading
for (int thisLed2 = bar2; thisLed2 < bar2+3; thisLed2++)
digitalWrite(ledPins2[thisLed2], HIGH);
}
delay(1000);
}
}