Discussion in 'Programmer's Corner' started by neo1111, Jan 11, 2015.

  1. neo1111

    Thread Starter New Member

    Jan 11, 2014
    Hi there!
    I want to make a program that reads the movement on X and Y axis and turns a LED on.
    For mevement on X axis-turn on Red led and for movement on Y axis-turn on Yellow led.
    For the X axis it's ok but i can't find watt's wrong for the Y axis.
    Any ideas.

    Here is the program(what must me changed in order to turn the Yellow Led for the Y axis?):

    #define PRAG_X_1 0.5
    #define PRAG_X_2 1
    #define PRAG_X_3 2
    #define PRAG_Y_1 0.5
    #define PRAG_Y_2 1
    #define PRAG_Y_3 2
    #define SMOOTH_X 0.4
    #define SMOOTH_Y 0.4
    void setup(){
    pinMode(2, OUTPUT);
    pinMode(8, OUTPUT);
    pinMode(13, OUTPUT);
    digitalWrite(2, HIGH);
    float oldAccX;
    float oldAccY;
    void loop() {
    float accX = smooth(readAcc(0), SMOOTH_X, oldAccX);
    float accY = smooth(readAcc(1), SMOOTH_Y, oldAccY);
    if (accX < -PRAG_X_2){
    digitalWrite(13, HIGH);
    else {
    digitalWrite(13, LOW);
    if (accY < -PRAG_Y_2){
    digitalWrite(8, HIGH);
    else {
    digitalWrite(8, LOW);
    float readAcc(int port) {
    int value=analogRead(port);
    int miliVolts=map(value,0,,1023,0,3300)-3300/2;
    float acc=(float)miliVolts/360;
    return acc;
    float smooth(float data, float filterVal, float smoothedVal) {
    if (filterVal > 1) {
    filterVal = .99;
    else if (filterVal <= 0){
    filterVal = 0;
    smoothedVal = (data * (1 - filterVal)) + (smoothedVal * filterVal);
    return (float)smoothedVal;
    } DSC_0157.JPG
    Last edited by a moderator: Jan 11, 2015
  2. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    1. Pick a better subject line when posting "HELP NEEDED" is obnoxious and doesn't tell anything about your post.

    2. When you post code, post it between code tags. That is the word code enclosed in square brackets with /code enclosed in square brackets for the ending tag.

    3. No one is going to do your work for you. What have you done to troubleshoot your code? Where are you having problems? We can help but you are the one with all of the code and the hardware. Do you really expect someone to follow your code line by line just looking at it and figure it out? It is always best to start simple. First just get the LEDs to turn off and on by forcing them off and on. Forget about the rest of the code. Write a simple test program if you have too. Then move on to read you axis hardware. Se if you can read it. Again write a test program.

    4. Exactly what is the purpose of the giant photos? They really serve no purpose other than to show you are using an Arduino which you could have easily mentioned in your text rather than making your post annoyingly large in size.
  3. WBahn


    Mar 31, 2012
  4. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    And remove those photos! They are taking the page forever to load.