Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Symbolls

Arduino display and rodory encoder

4 hours ago, Symbolls said:

Hi thx for the time to answer but it dont understand how i can implement this in the code bechose i am noob to programing and i cant figure it out. I have benn resercing about this and i am just to dumb.

yeah sure, here's some readings on what I did, they're fairly basic c++ concepts https://www.geeksforgeeks.org/decision-making-c-c-else-nested-else/

http://www.cplusplus.com/doc/tutorial/variables/ https://www.geeksforgeeks.org/switch-statement-cc/

^these two sites got me through my CS 100 class a couple years ago, absolute god sends. Whenever you see some code that you don't understand, google it and you'll find a ton of information on it. To get the encoder working, have a look at this video 

 

I'll also comment line by line what that little snippet of code does

Spoiler

//this should just be part of your program to handle the UI element of the project, you'll need more stuff to get the screen and whatever else working.

int select = 0;//declare a variable to keep track of what menu state we're in. We can add 1 to this value by 
			    //triggering some input to the system, then based on its value decide what other parts of 
				// the program do

int max = x; //maximum number of states you want in the program, or you could also use this as a maximum number of menu screens
//this bit of code reads the push button on the encoder and uses it to decide when to increment the select variable.
//the encoder has what's called a pullup resistor, meaning that in the unpressed state, the signal from the encoder is high, or 5v
//when the button is pushed, the switch pin is connected to ground, pulling the signal to 0v or low.
if(digitalRead(SW)==LOW){//I took a bit of liberty here, I made up the variable SW for switch. Whatever pin you plug the button into on your 
  						//arduino should be put here. It's nice to use a variable that you declare globally (google C++ global variable)
  						//so that when you read through the code you know what is being read because you used a descriptive variable name
  						//instead of a cryptic number that correseponds to a pin
  select++;//++ adds one to whatever variable
    if(select>max){//this if statement just resets the select variable to 0 after you try to go past the last state
    select = 0;
  }
}
//this is the fun part. Switch cases are super powerful for things like this project because they can cycle through however many states as you define
//to do whatever you want. So when the select variable = 1, the code executes what is written at case 1. Once it finishes that snippet of code, it 
//reaches the break; statement, which breaks out of the switch case for that iteration of the program. If you don't have the break statement, the 
//code will keep running line by line through the other cases, which is generally not the desired effect.
switch(select){
  case 1://state 1
    break;
  case 2://state 2
    break;
  case n: //nth state
    break;
}

 

 

Recommended Posts

Posted · Original PosterOP

Hallo! I am building a macine that moves some motors in fuctun with how muthc i input on a display.I have a rodory encoder that controls how mutch the motor shud go but i dont know how to make 2 coloms on the display and make the push of the rodory encoder to swith witch part i control and also how i thie it up with the motors. And btw i am using a arduino mega .Thx for reading.The code and some imiges are atached(Sorry for my gramar i am not a native speaker) 20200904_125637.thumb.jpg.8abf129f497bce1b7744a0e7a3b4e619.jpg

Rodory_and_display.ino

Link to post
Share on other sites

Hey, cool little project you have here! 

 

So let me get this straight: You want to use the rotary encoder you have there to drive a motor a certain number of steps (Assuming stepper motor) 

 

Before you deal with adding the LCD I would advise you to get the system working as you intend, THEN add the LCD side of things. I glanced at your code and it looks like you have a bit of a way to go. I'd suggest taking a look at this guide and snagging some of the code from it to do what you want: https://www.arduino.cc/en/Tutorial/MotorKnob#:~:text=In this example%2C a potentiometer,either unipolar or bipolar motors.

Link to post
Share on other sites

To make a second column, I believe you just need to relocate your cursor and print the second variable. To get the switch to control the different functions, I would do something like

int select = 0;
int max = x; //maximum number of states you want in the program
if(digitalRead(SW)==LOW){//that encoder has a pullup so when it is pressed, the signal becomes low from a high state
  select++
    if(select>max){
    select = 0;
  }
}
switch(select){
  case 1://state 1
    break;
  case 2://state 2
    break;
  case n: //nth state
    break;
}

I've done similar projects in the past making a very very basic UI with little arduino screens. Switch cases are generally the way to go, with a button to increment a counter to select a function/menu.


ASU

Link to post
Share on other sites
Posted · Original PosterOP
On 9/4/2020 at 8:18 PM, Hackentosher said:

To make a second column, I believe you just need to relocate your cursor and print the second variable. To get the switch to control the different functions, I would do something like


int select = 0;
int max = x; //maximum number of states you want in the program
if(digitalRead(SW)==LOW){//that encoder has a pullup so when it is pressed, the signal becomes low from a high state
  select++
    if(select>max){
    select = 0;
  }
}
switch(select){
  case 1://state 1
    break;
  case 2://state 2
    break;
  case n: //nth state
    break;
}

I've done similar projects in the past making a very very basic UI with little arduino screens. Switch cases are generally the way to go, with a button to increment a counter to select a function/menu.

Hi thx for the time to answer but it dont understand how i can implement this in the code bechose i am noob to programing and i cant figure it out. I have benn resercing about this and i am just to dumb.

Link to post
Share on other sites
Posted · Best Answer
4 hours ago, Symbolls said:

Hi thx for the time to answer but it dont understand how i can implement this in the code bechose i am noob to programing and i cant figure it out. I have benn resercing about this and i am just to dumb.

yeah sure, here's some readings on what I did, they're fairly basic c++ concepts https://www.geeksforgeeks.org/decision-making-c-c-else-nested-else/

http://www.cplusplus.com/doc/tutorial/variables/ https://www.geeksforgeeks.org/switch-statement-cc/

^these two sites got me through my CS 100 class a couple years ago, absolute god sends. Whenever you see some code that you don't understand, google it and you'll find a ton of information on it. To get the encoder working, have a look at this video 

 

I'll also comment line by line what that little snippet of code does

Spoiler

//this should just be part of your program to handle the UI element of the project, you'll need more stuff to get the screen and whatever else working.

int select = 0;//declare a variable to keep track of what menu state we're in. We can add 1 to this value by 
			    //triggering some input to the system, then based on its value decide what other parts of 
				// the program do

int max = x; //maximum number of states you want in the program, or you could also use this as a maximum number of menu screens
//this bit of code reads the push button on the encoder and uses it to decide when to increment the select variable.
//the encoder has what's called a pullup resistor, meaning that in the unpressed state, the signal from the encoder is high, or 5v
//when the button is pushed, the switch pin is connected to ground, pulling the signal to 0v or low.
if(digitalRead(SW)==LOW){//I took a bit of liberty here, I made up the variable SW for switch. Whatever pin you plug the button into on your 
  						//arduino should be put here. It's nice to use a variable that you declare globally (google C++ global variable)
  						//so that when you read through the code you know what is being read because you used a descriptive variable name
  						//instead of a cryptic number that correseponds to a pin
  select++;//++ adds one to whatever variable
    if(select>max){//this if statement just resets the select variable to 0 after you try to go past the last state
    select = 0;
  }
}
//this is the fun part. Switch cases are super powerful for things like this project because they can cycle through however many states as you define
//to do whatever you want. So when the select variable = 1, the code executes what is written at case 1. Once it finishes that snippet of code, it 
//reaches the break; statement, which breaks out of the switch case for that iteration of the program. If you don't have the break statement, the 
//code will keep running line by line through the other cases, which is generally not the desired effect.
switch(select){
  case 1://state 1
    break;
  case 2://state 2
    break;
  case n: //nth state
    break;
}

 

 


ASU

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


×