Go Down

Topic: Project problem (Read 321 times) previous topic - next topic

sieminek

Dec 05, 2012, 12:14 am Last Edit: Dec 05, 2012, 05:31 pm by sieminek Reason: 1
I have made a simple 6x6 LOL and it works fine. I decided to use a MMA7361 accelerometer to control the position of the lit up LED on the LOL. (Tilt away light moves up, tilt towards light moves down you get the idea). So it looks like it works fine but I have a problem with the first column of the LOL. When I tilt the whole thing to the left as the light reaches the first column it disappears, when you tilt it down where the light is supposed to reach the bottom of the LOL and then tilt right the light appears where you would expect it to be, at the bottom of the LOL. (All LEDs are working)
For some reason I decided to expand some of the loops in the program trying to solve it. Still doesn't work..


This is the code that I am using.
Code: [Select]

//X=470
//Y=360
//Z=350

int XPin = A2; // X
int YPin = A1; // Y
int ZPin = A0; // Z
int valX = 0;
int valY = 0;
int valZ = 0;

int vert=3;
int hoz=7;

void setup() {
 Serial.begin(9600);
 pinMode(0, OUTPUT);
 pinMode(1, OUTPUT);
 pinMode(2, OUTPUT);
 pinMode(3, OUTPUT);
 pinMode(4, OUTPUT);
 pinMode(5, OUTPUT);
 pinMode(6, OUTPUT);
 pinMode(7, OUTPUT);
 pinMode(8, OUTPUT);
 pinMode(9, OUTPUT);
 pinMode(10, OUTPUT);
 pinMode(11, OUTPUT);
 pinMode(12, OUTPUT);
 pinMode(13, OUTPUT);
 for(int x=0; x<8; x++){
   digitalWrite(x, LOW);
 }
 for(int x=7; x<14; x++){
   digitalWrite(x, HIGH);
 }
}


void loop() {
 digitalWrite(0, HIGH);
 valX = analogRead(XPin);
 valY = analogRead(YPin);
 valZ = analogRead(ZPin);  

 Serial.print(" X-");
 Serial.print(valX);
 Serial.print(" Y-");
 Serial.print(valY);
 Serial.print(" Z-");
 Serial.print(valZ);
 Serial.print("\n");

 int updown=valY-350;
 int sides=valX-350;

 if (sides<-75 && vert!=1){
   vert=vert-1;
 }

 if (sides>75 && vert<6){
   vert=vert+1;
 }

 if (updown<-75 && hoz<12){
   hoz=hoz+1;
 }

 if (updown>75 && hoz>7){
   hoz=hoz-1;
 }

 digitalWrite(hoz, LOW);
 digitalWrite(vert, HIGH);
 digitalWrite(hoz, HIGH);
 digitalWrite(vert, LOW);
}

If you would like to see the circuit drawing please just ask.
Thank you.

PeterH

What ranges of values do you intend vert and hoz to take?

Oh, and please put your code in [ code ] [ /code ] tags - you can click the # button in the edit window to insert them.
I only provide help via the forum - please do not contact me for private consultancy.

PaulS

Code: [Select]
  Serial.begin(9600);
  pinMode(0, OUTPUT);
  pinMode(1, OUTPUT);

Do you want to use those pins for Serial or for LEDs? Choose ONE.

sieminek

Sorry, I'm new to this.
Values for hoz 7 to 12, vert 1 to 6.

All the digital pins apart from 0 are for the LED (1-12)

PaulS

You can not use digital pins 0 and/or 1 while also using Serial.

sieminek

Thanks lots!!! I just moved up the whole digital set of LEDs by 1. It works now. Thank you very much. :)

Go Up