hi i have mma7361 and tlc5940 setup to display the angles of tilt on leds and also a lcd display the code works good and display works as well i have a problem with the leds flashing and no being solid between channels if i use Tlc.clear();
on the pinsx
the bottom row stays lit solid and top row flashes same if i do same for
pinsy
but if use Tlc.clear();
on both parts of code the leds flash between themselves
////////////////////
#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 pinsx[] = {
1,2,3,4,5,6,7,8,9,10};
int pinsy[] = {
17,18,19,20,21,22,23,24,25,26};
const int yledCount = 10; // the number of LEDs in the bar graph
const int xledCount = 10; // the number of LEDs in the bar graph
const int buttonPin = 52; // the number of the pushbutton pin
const int ledPin = 6;
// 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);
digitalWrite(selPin,LOW);
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:
pinMode(buttonPin, INPUT);
Tlc.init();
}
void loop() {
buttonState = digitalRead(buttonPin);
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");
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
}
else {
// turn LED off:
digitalWrite(ledPin, LOW);
int xbar1 = map(degxValue, 90, -90, 0, 9);
int xbar = constrain(xbar1, 0, 10);
for (int channel = xbar; channel < xbar+1; channel++)
Tlc.set(pinsy[channel], 1110);
Tlc.update();
delay(300);
int ybar1 = map(degyValue, 90, -90, 0, 9);
int ybar = constrain(ybar1, 0, 10);
for (int channel = ybar; channel < ybar+1; channel++)
Tlc.set(pinsx[channel], 1110);
Tlc.update();
delay(300);
Tlc.clear();
}
}
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;
}