hi could you please help me with my work project code the idea of the hardware is so on the back of a work machine it visual display of angle of machine with leds i have the code working so it lights one led on each direction of angle but cant seem to figure out how to light all the leds in the direction of travel so if it center 1 led is lit but if it is angle left at 90 degrees all the leds in that direction would be lit here is my code thanks for looking
#include "Tlc5940.h"
#include <math.h>
#define M_PI 3.1415926535897932
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(43, 39, 35, 33, 31, 29);
int pinsy[] = {
1,2,3,4,5,6,7,8,9,10,11,12,13,14,17,18,19,20,21};
int pinsx[] = {
22,23,24,25,26,27,28,29,30,33,34,35,36,37,38,39,40,41,42};
const int yledCount = 19; // the number of LEDs in the bar graph
const int xledCount = 19; // the number of LEDs in the bar graph
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
int xPin = 0;
int yPin = 1;
int selPin = 42;
int sleepPin = 44;
float xValue, yValue, zValue;
float gxValue, gyValue, gzValue;
float degxValue, degyValue, degzValue;;
const float scalePoints = 1023/5;
float calValues[4] = {0,0};
int numReadings = 0;
int maxNumReadings = 20;
long dt = 250;
long lastTime = 0;
void setup() {
Serial.begin(9600);
digitalWrite(sleepPin,HIGH);
analogReference(EXTERNAL);
getCalValues();
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// loop over the pin array and set them all to output:
// set up the LCD's number of columns and rows:
Tlc.init();
}
void loop() {
xValue = analogRead(xPin);
yValue = analogRead(yPin);
gxValue = constrain((xValue/scalePoints-1.65-calValues[0])/0.8,-1,1);
gyValue = constrain((yValue/scalePoints-1.65-calValues[1])/0.8,-1,1);
degxValue = asin(gxValue)/M_PI*180;
degyValue = asin(gyValue)/M_PI*180;
Serial.print(degxValue,1); Serial.print(" "); lcd.setCursor(2,0); lcd.print( "U + D = "); lcd.print(degxValue,0 ); lcd.print(" Deg ");
Serial.print(degyValue,1); Serial.print(" "); lcd.setCursor(2,2); lcd.print( "L + R = "); lcd.print(degyValue,0 ); lcd.print(" Deg ");
Serial.println("\t"); Serial.println("\t");
int xbar1 = map(degxValue, -90, 90, 0, 19);
int xbar = constrain(xbar1, 0, 19);
for (int channel = xbar; channel < xbar+1; channel++) {
Tlc.set(pinsy[channel], 4095);
int ybar1 = map(degyValue, -90, 90, 0, 19);
int ybar = constrain(ybar1, 0, 19);
for (int channel = ybar; channel < ybar+1; channel++) {
Tlc.set(pinsx[channel], 4095);
{
Tlc.update();
Tlc.clear();
delay(950);
break;}
}
}
}
void getCalValues() {
while (numReadings < maxNumReadings)
if (millis() - lastTime > dt) {
calValues[0] = calValues[0] + analogRead(xPin);
calValues[1] = calValues[1] + analogRead(yPin);
lastTime = millis();
numReadings++;
}
calValues[0] = (calValues[0] / maxNumReadings)/scalePoints-1.65;
calValues[1] = (calValues[1] / maxNumReadings)/scalePoints-1.65;
}