Go Down

Topic: need help, i will pay $$$ (Read 607 times) previous topic - next topic

whitelion1987

Aug 11, 2019, 10:33 pm Last Edit: Aug 12, 2019, 01:58 am by whitelion1987
need help with coding:
when limit back ==LOW - reach i won it if take steps and read 3.3v or 0v for sensor 11 pin
1. outA = 400; (from 0 - 400 steps - 3.3v)
2.than in = 17000; (from 401 - 17400steps -0v)
3. outB = 4000; (from 17401 - 21400steps -3.3v)
4.when all steps reach then need send till front limit reach and is == low and show 3.3v
some think like that

int sensor = 11; 
int outA;
int in;
int outB;
long allSteps;
// void setup

pinMode (sensor, OUTPUT);
outA = 400;
in = 17000;
outB = 4000;


//  void loop

if(value_limitBack == LOW) //when low need if start reading steps and 3.3v or 0v
{
 outA-400 steps-3.3v  {
  analogWrite (sensor,170);
   }
   in-17000 steps-0v {
    analogWrite (sensor,0);
   }
  outb-4000steps -3.3v){
  analogWrite (sensor,170);     after reach all steps if send to front limit and stops
  }
  if(value_limitFront == LOW) {
    analogWrite (sensor,170);
  }
i'm not programmer and looks terrible but i hope understand what i won it

zwieblum

Aehm ... what is the question?

wvmarle

Please go and read the How to use this Forum sticky first.

Then you know not only how to properly post code, but also what kind of other information we need about your project, as for now I have no idea what you have and what you want changed.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

zwieblum

"need for that code:" and presenting "the code" is no question, its like saying "nee that apple:" and presenting an apple to a person - now does that mean "A wants that apple and asks B if he can have it" or does it mean "B, do you want this apple?" or is it something totally different, e.g. "B, is this an apple I could need?"

wvmarle

Nice analogy, but you forgot to add: "... without saying what that apple would possibly be used for".
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

zwieblum

Sorry, but I still have not found the question.

Hiddenvision

#6
Aug 12, 2019, 10:39 pm Last Edit: Aug 12, 2019, 11:27 pm by Hiddenvision
So I get it a little.
I can see the question or "I need" part
but not 100% understanding either.

Getting two voltages from the same pin is hard.
perhaps use two pins with a resistor divider setup.
Is analogwrite a pwm function ? there is no DAC on the atmels?

Unless you mean you only need 3.3v maximum to sensor.
If so then it is easy, my confusion.

What you need, counting and changing a pin or two, is easy to do
 but I think the hard part is the understanding exactly your needs

This is at least more readable to start.

Code: [Select]


//sorry,but i new,im not programmer and it is not my 1st language....post #2 is code what i have at that moment fully working
//-moving table-
//when turn on move automatic to front position(limitFront),
//when press btnfront table move till backlimit reach,
//if press btnback send to front position till limit front reach...

//i won it emulate signal fro  PHOTO INTERRUPTER SENSOR( on arduino nano PIN11 and put in on that #2  code)-
//sends high or low on correct position and correct time count steps and voltage..
//on arduino nano means 5v and 0v,
//but i need 3.3v and 0v for that can use analogwrite....

//i need when limit back is pressed/low it start to count
//when stepper motor moves-400 motor steps and give 3.3v(on digital pin 11),
//after 17000 motor steps give 0v(on digital pin 11),
//after 4000 motor steps  and give 3.3v(on digital pin 11),
//when all steps done-count need
//if send automatic  till front limit reach and show 3.3v (on pin 11)and stops

#include <Bounce2.h>
#define Pin_btnFront 4
#define Pin_btnBack 5

#define Pin_motorDir 6
#define Pin_motorStep 7
#define Pin_limitBack 9
#define Pin_sensor 11
#define Pin_limitFront 12
#define Pin_enable 13

int COUNT_outA = 400; //steps 3.3v
int COUNT_in = 17000; //steps 0v
int COUNT_outB = 4000; //steps 3.3v
long COUNT_allSteps = 21400;

int stepcount = 0;

// Instantiate a Bounce object
Bounce btnFront = Bounce();
Bounce btnBack = Bounce();
Bounce limitBack = Bounce();
Bounce limitFront = Bounce();

boolean do_front = false;
boolean do_back  = false;

void setup() {
  pinMode(Pin_sensor, OUTPUT);
  digitalWrite(Pin_sensor, LOW);
 
  pinMode(Pin_motorDir, OUTPUT);
  pinMode(Pin_motorStep, OUTPUT); 
  pinMode(Pin_enable, OUTPUT);
  digitalWrite(Pin_enable, HIGH);

  // Setup the first button with an internal pull-up :
  pinMode(Pin_btnFront, INPUT_PULLUP);
  // After setting up the button, setup the Bounce instance :
  btnFront.attach(Pin_btnFront);
  btnFront.interval(5); // interval in ms

  pinMode(Pin_btnBack, INPUT_PULLUP);
  btnBack.attach(Pin_btnBack);
  btnBack.interval(5);

  pinMode(Pin_limitFront, INPUT_PULLUP);
  limitFront.attach(Pin_limitFront);
  limitFront.interval(5);

  pinMode(Pin_limitBack, INPUT_PULLUP);
  limitBack.attach(Pin_limitBack);
  limitBack.interval(5);
 
  goFront();
}

void stepmotor (int dval){
  digitalWrite(Pin_motorStep, HIGH);
  delayMicroseconds(dval);
  digitalWrite(Pin_motorStep, LOW);

//  if (do_back){stepcount--;}
//  if (do_front){stepcount++;}
  stepcount++;
  if (stepcount == COUNT_outA){;}
  if (stepcount == COUNT_outB){;}
  if (stepcount == COUNT_in){;}
 
}

void goBack() {
  digitalWrite(Pin_motorDir, HIGH);
  limitBack.update();
  stepcount = 0;
  while (limitBack.read() == HIGH) {
    //btnBack.update(); if (btnBack.read() != LOW) {break;}
    stepmotor (250);   
    btnFront.update();
    if (btnFront.read() == LOW) {
      do_back = false;
      do_front = true;
      return;
    }
    limitBack.update();
  }
  do_back = false;
  do_front = false;
}

void goFront() {
  digitalWrite (Pin_motorDir, LOW);
  limitFront.update();
  stepcount = 0;
  while (limitFront.read() == HIGH) {
    //btnFront.update(); if (btnFront.read() != LOW) {break;}
    stepmotor (250);   
    btnBack.update();
    if (btnBack.read() == LOW) {
      do_back = true;
      do_front = false;
      return;
    }
    limitFront.update();
  }
  do_back = false;
  do_front = false;
}

void loop() {
  // Update the Bounce instances :
  btnFront.update(); btnBack.update();
  limitFront.update(); limitBack.update();
 
  // Get the updated value :
//  int value_limitFront = limitFront.read();
//  int value_limitBack = limitBack.read();
 
  if (btnFront.read() == LOW) {do_front = true;}
  if (btnBack.read() == LOW) {do_back = true;}

  if (do_front) {goFront();}
  if (do_back) {goBack();}
}


UKHeliBob

Quote
post #2 is code what i have at that moment
Not a lot then
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Go Up