void mouth() {
drawEllipse(75, 30, 50, 35);
delay(200);
drawEllipse(60, 17, 40, 47);
delay(200);
eraseEllipse(60, 17, 40, 47);
drawEllipse(30, 17, 20, 47);
delay(200);
eraseEllipse(30, 17, 20, 47);
delay(200);
drawEllipse(60, 8.5, 40, 23.5);
delay(200);
eraseEllipse(60, 8.5, 40, 23.5);
delay(200);
drawEllipse(50, 9, 50, 17);
eraseEllipse(50, 9, 50, 17);
delay(200);
}
void eyes() {
setPixel(35, 50);
setPixel(65, 50);
drawEllipse(30, 55, 40, 45);
delay(300);
drawEllipse(60, 55, 70, 45);
delay(300);
eraseEllipse(30, 55, 40, 45);
delay(300);
eraseEllipse(60, 55, 70, 45);
}
task main() {
drawEllipse(18, 64, 82, 0);
while(1){
eyes();
mouth();
}
#pragma config(Sensor, S1, touch, sensorTouch)
#pragma config(Sensor, S2, sound, sensorSoundDB)
#pragma config(Sensor, S3, light, sensorLightActive)
#pragma config(Sensor, S4, sonar, sensorSONAR)
#pragma config(Motor, motorA, clawMotor, tmotorNXT, PIDControl, encoder)
#pragma config(Motor, motorB, rightMotor, tmotorNXT, PIDControl, driveRight, encoder)
#pragma config(Motor, motorC, leftMotor, tmotorNXT, PIDControl, driveLeft, encoder)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
const int speed = 50;
const float WheelDiameter = 5.6;
const float WheelCircumference = WheelDiameter*PI;
//Encoder ticks = (distance / circumference) * 360
void forward();
void stopBot();
void distToTravel(float dist);
int distToTicks(float dist);
void spinDegrees(int turn);
int degToTicks(int turn);
void turnRight();
const int width = 16
const float turnCircumference = width*PI
task main(){
distToTravel(10);
spinDegrees(150);
}
void stopBot(){
motor[motorB]=0;
motor[motorC]=0;
}
void turnRight(){
motor[motorB] = 50;
motor[motorC] = -50;
}
void spinDegrees(float turn) {
int ticksToTurn = degToTicks(turn);
nMotorEncoder[motorC] = 0;
turnRight();
while(nMotorEncoder[motorC] <= ticksToTurn);
stopBot();
}
int degToTicks(int turn) {
return turnCircumference/(360/turn)
}
void forward() {
motor[motorB] = speed;
motor[motorC] = speed;
}
void distToTravel(float dist) {
int ticksToGo = distToTicks(dist);
nMotorEncoder[motorC] = 0;
forward();
while(nMotorEncoder[motorC] <= ticksToGo);
stopBot();
}
int distToTicks(float dist) {
return dist/WheelCircumference * 360;
}
/function declarations
//1) what is the function returning if anything?
//basic options: void = returning nothing, int = return whole number, float = return decimal number
//2) function name
//3) datatypes & names of parameters if any inside paranthesis
//4) ;
float divide(int divisor, int dividend);
task main()
{
float divisor = 0;
float dividend = 0;
float q1 = 0;
float q2 = 0;
divisor=50;
dividend=5;
q1 = divide(divisor,dividend); //(int x, int y)
displayTextLine(0, "%d/%d=%d",divisor,dividend, q1);
divisor=1;
dividend=3;
q2 = divide(divisor, dividend); //(int x, int y)
displayTextLine(1, "%d/%d=%f",divisor,dividend, q2);
}
//function definitions
//1) copy & paste the declaration, remove ;, and add {}'s
float divide(int divisor, int dividend)
{
return (float)divisor/dividend;
}