Barobo
PortalSign In
HomeShopTutorialsFree CurriculumHour of Code
RoboBlockly for Learning Math and Coding

Use a Joystick to Control LEDs

Piano
Linkbot Image Mindstorm Image Cursor Image
0x2418126-6-12y2418126-6-12
Grid:
Tics Lines:
Width px
Hash Lines:
Width px
Labels:
Font px
Trace Lines:
Robot 1:
Width px
Robot 2:
Width px
Robot 3:
Width px
Robot 4:
Width px
Labels: x-axis y-axis Show Grid
Grid: 12x12 inches 24x24 inches 36x36 inches
72x72 inches 96x96 inches 192x192 inches
Quad: 4 Quadrants 1 Quadrant 1&4 Quadrants
Units: US Customary Metric
Background: Background Image

Robot 1

Linkbot
Mindstorm
Initial Position:
( in, in)
Initial Angle:
deg
Current Position: (0 in, 0 in)
Current Angle: 90 deg
Wheel Radius:
Track Width:
in

Robot 2

Linkbot
Mindstorm
Initial Position:
( in, in)
Initial Angle:
deg
Current Position: (6 in, 0 in)
Current Angle: 90 deg
Wheel Radius:
Track Width:
in

Robot 3

Linkbot
Mindstorm
Initial Position:
( in, in)
Initial Angle:
deg
Current Position: (12 in, 0 in)
Current Angle: 90 deg
Wheel Radius:
Track Width:
in

Robot 4

Linkbot
Mindstorm
Initial Position:
( in, in)
Initial Angle:
deg
Current Position: (18 in, 0 in)
Current Angle: 90 deg
Wheel Radius:
Track Width:
in
Use a Joystick to Control LEDs
/* Code generated by RoboBlockly v2.5 */
/* Problem Statement: 
    Modify the code so that it uses the green and blue LEDs
    instead of red and green.
    */
#include <arduino.h>
double thebutton;
double xvalue;

// Set pins for blue and green LED to output
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
// Set pin for the joystick button to input
pinMode(2, INPUT);
// Set pin for joystick x value to input
pinMode(A1, INPUT);
// Set value of button variable to 0 (unpressed)
thebutton = 0;
// Keep reading button until pressed (nonzero value)
while(thebutton == 0) {
  // Get joystick x reading
  xvalue = analogRead(A1);
  // If x value is high, turn on green LED (else off)
  if (xvalue > 712) {
    digitalWrite(12, HIGH);
  }
  else {
    digitalWrite(12, LOW);
  }
  // If x value is low, turn on blue LED (else off)
  if (xvalue < 312) {
    digitalWrite(11, HIGH);
  }
  else {
    digitalWrite(11, LOW);
  }
  // Delay 0.1 seconds so don't overload reading
  delay(100);
  // Read the value of joystick button (1 if pressed)
  thebutton = digitalRead(2);
}
// Joystick button was pressed, so loop ends
Load Blocks
Hardware
LArduino
Workspace Show Ch Save File
Problem Statement:

Modify the code so that it uses the green and blue LEDs instead of red and green.


		
Rubbish bin
Time