View unanswered posts | View active topics It is currently Tue Aug 04, 2020 7:31 am

 Page 1 of 1 [ 1 post ]
 Print view Previous topic | Next topic
PLTW Vex Elevator code
Author Message
Rookie

Joined: Wed May 04, 2016 11:24 pm
Posts: 1
PLTW Vex Elevator code
Hi, in my engineering class in school I was instructed to design an elevator with three floors where when each bump switch was pressed, the elevator would move to that floor with its corresponding LED lighting up (floor 1: green, 2: yellow, 3: red). In my class, we haven't learned how to create a toggle out of a bump switch so I tried my best to create a piece of code that would move the elevator if the bump switch was held down. I'm not sure if this works yet because I simply typed it up in a notepad document at home because I don't have the Robot C software at home or my physical project with me. I was wondering if someone could take a look at what I wrote to:
1. Tell me if it works or not regardless of how awkward the inputs might be
2. Give me and pointers on how to improve or optimize it
3. Show me a simple way to create a toggle on the switch so the if requirement isn't just if(SensorValue[bumpn]==1)

btw I am using the PLTW software on robot C in Natural Language

Thank you to anyone who responds and can help me out

code:

int bottom == .1 //check to make sure these values are correct for where you want the elevator to stop at, in inches//
int middle == 2.5
int top == 5

void f1 ()

void f2 ()

void f3 ()

void elevatorfcn ()

void timeout ()

cleartimer[T1]

{
while(1==1)
{
if(timer1[T1]<30000)
{
elevatorfcn ();
}
else if(time1[T1]==30000)
{
timeout ();
}
}
}

void f1 ()
{
while(1==1)
{
if(SensorValue[bump1]==1 && SensorValue[sonar]>.1)
{
cleartimer[T1];
turnLEDOn(G);
startMotor(elevator, 63); //make sure to test if down or up is negative or positive on the power value//
untilsonarlessthan(.2, sonar);
stopMotor(elevator);
}
}
}

void f2 ()
{
while(1==1)
{
if(SensorValue[bump2]==1 && SensorValue[sonar]<2.5)
{
cleartimer[T1]
turnLEDOn(Y);
startMotor(elevator, 63);
untilsonargreaterthan(2.5, sonar);
stopMotor(elevator);
}
else if(SensorValue[bump2]==1 && SensorValue[sonar]>2.5)
{
cleartimer[T1];
turnLEDOn(Y);
startMotor(elevator, -63);
untilsonarlessthan(2.6, sonar);
stopMotor(elevator);
}
}
}

void f3 ()
{
while(1==1);
{
if(SensorValue[bump3]==1 && SensorValue[sonar]<5)
{
cleartimer[T1];
turnLEDOn(R);
startMotor(elevator, 63);
untilSonargreaterthan(4.9, sonar);
stopMotor(elevator);
}
}
}

void elevatorfcn ()
{
while(1==1)
{
f1 ();
f2 ();
f3 ();
}
}

void timeout ()
{
turnLEDOn(G);
startMotor(elevator, -63)
untilsonarlessthan(.2, sonar);
stopMotor(elevator);
}

Wed May 04, 2016 11:34 pm
Display posts from previous:  Sort by
 Page 1 of 1 [ 1 post ]

#### Who is online

Users browsing this forum: No registered users and 1 guest

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ ROBOTC Applications    ROBOTC for LEGO MINDSTORMS       Third-party sensors    ROBOTC for CORTEX & PIC    ROBOTC for VEX IQ    ROBOTC for Arduino    Robot Virtual Worlds    Multi-Robot Communications    Issues and Bugs Competitions & Partners    Mini Urban Challenge    CS2N Robot Virtual Worlds Competitions       VEX Skyrise Competition 2014-2015       VEX Toss Up 2013-2014       FTC Block Party! 2013-2014    Competitions using VEX - BEST, TSA, VEX, and RoboFest!    FTC Programming    RoboCup Junior and Other ROBOT Competitions Virtual Brick Robotics Discussions    General Discussions    Project Discussions Off-Topic ROBOTC Forum & ROBOTC.net Suggestions/Feedback    ROBOTC Forums Suggestions/Comments    ROBOTC.net Suggestions/Comments       NXT Programming: Tips for Beginning with ROBOTC       VEX Programming: Tips for Beginning with ROBOTC    2013 Robotics Summer Of Learning       VEX Toss Up Programming Challenge       FTC Ring It Up! Programming Challenge    International Forums       Spanish Forums          ROBOTC for MINDSTORMS          ROBOTC for VEX       French Forums          ROBOTC pour Mindstorms          ROBOTC pour IFI VEX       Japanese Forums （日本語のフォーラム）       German Forums    2015 Spring Carnival Event    PLTW (Project Lead The Way)    Robotics Merit Badge    2014 Robotics Academy Summer of Learning