Program Questions: Reply Rly. Fast!!

i will not be able to post pictures by then i am sorry. i will do whatever i can to help you out here though. why don’t you try sunny’s code that he posted.

i’ll try. hope it works!

Sunny, i dont think your code will work

look at the picture here https://vexforum.com/wiki/images/f/ff/Optical_Shaft_Encoder_Figure_5.jpg
you will need to place you if loops where they have the print to screen icon.

what do i type and put in the if loop???:confused::confused::confused:

type either “true” or “1 == 1”

Yo Sunny, easyC uses 255 for forward lol
Your example seems to be in RobotC (which in my opinion is in some ways inferior to easyC… *)

But concept-wise, Sunny is correct
////////////////////////////////////////
long encoder_count = 0;

PresetEncoder(1,0); //Preset encoder value to 0
StartEncoder(1);

motor[port1]=255; //Run motor1
while(encoder_count<230)
{
encoder_count=GetEncoder(1); //Keep checking encoder value
}
motor[port1]=127; //Stop motor1*

C&P from the other thread:

long encoder_count = 0;

PresetEncoder(1,0); //Preset encoder value to 0
StartEncoder(1);

motor[port1]=255; //Run motor1
while(encoder_count<230)
{
encoder_count=GetEncoder(1); //Keep checking encoder value
}
motor[port1]=127; //Stop motor1

r u using easyC V2?

:confused:r u using easyC V2:confused:

I tried the code and when i try to donlowd it, the computer says: there was an error. it sayed different words tho

That is RobotC, but the concept is still the same.

we cant use that. we have to use easyC;)

Soapy,

Do you have a more specific question than the ones you have posted so far?

Aside from figuring out how to plug it in, the directions that came with the endcoders 4 years ago were pretty clear about how to use it. I assume that they have opnly improved since then.

What specifically is your need?

Are you unsure how to monitor a sensor and use the result to affect the rest of the machine’s operation? or are you confused about how to install or monitor this specific sensor (the encoder)?

Blake

Sorry. I need to get back to you soon. I’m experimenting with them. And i need a code for EasyC V2 to make motor 1 stop after 230 ticks of the encoder.:slight_smile:

Have you read the help information (about writing software) that comes in the Inventor’s Guide materials, and with EasyC?

What you want to do is at least 80-90% covered in those materials, if not 100%.

In a similar vein, if you post the software you have written so far, and describe what parts of it aren’t working the way you expected, you can ask forum readers to look for problems in your existing code.

If you just want some else to do everything for you; then you might have to wait a long time before you get that sort of response.

Blake

In general people do not like to spoon feed answers. You really should read up on the sensor because like Blake said they tell you most if not all of what you need to know.

Sometimes the best way to learn something is to goof around with it yourself. You aren’t going to learn anything if you take a picture posted on the forum and duplicate it.

People are happy to help you here but you need to provide them with what you have and exactly what you need. Spelling out your words works nicely too. Why don’t you post your code and let us try to find the issue with it.

Should I post a picture in the Gallery? And yes I have been Playing with the Sofware and the program and some codes.

Never mind. I’ll say the code.

SetMotor ( 6 , 127 )
SetMotor (5 , 127)
while ( 1==1 )
{
Arcade2 ( 1 , 1 , 2 , 2 , 1 , 1 , 0 ) ;
Tank2 ( 1 , 3 , 4 , 5 , 6 , 0 , 0 ) ;
Up = GetDigitalInput ( 5 ) ;
if ( Up == Active )
{
SetMotor ( 5 , 255 ) ;
Wait ( 300 ) ;
SetMotor ( 5 , 127 ) ;
}
Down = GetDigitalInput ( 6 ) ;
if ( Down == Active )
{
SetMotor ( 5 , 255 ) ;
Wait ( 500 ) ;
SetMotor ( 5 , 127 ) ;
}
Open = GetDigitalInput ( 7 ) ;
if ( Open == Active )
{
SetMotor ( 6 , 90 ) ;
Wait ( 300 ) ;
SetMotor ( 6 , 127 ) ;
}
Closed = GetDigitalInput ( 8 ) ;
if ( Closed == Active )
{
SetMotor ( 6 , 165 ) ;
Wait ( 500 ) ;
SetMotor ( 6 , 127 ) ;
}
while ( 1==1 )
{
Position = GetAnalogInput ( 1 ) ;
Position2 = GetAnalogInput ( 2 ) ;
PrintToScreen ( “Position =%d\n” , (int)Position ) ;
PrintToScreen ( “Position2 ===%d\n” , (int)Position ) ;
PrintToScreen ( “Next\n” ) ;
Wait ( 2000 ) ;
}
}
}

I don’t see any attempt to use an encoder.

I use RobotC and easyC V2 conditionally
If you’re wondering about my syntax, ignore it
I made up my own syntax in that example, since I assumed you just wanted the general concept of how the Encoder-Motor code worked
I it didn’t make it too hard to understand
The Encoder commands should be the same as easyC V2, though
The motor syntax is more like RobotC (except for the values, since RobotC operates on a -127 to 127 value range for motors[and I assumed you were using easyC V2 so I used 0 to 255 as the value range in the example])