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

Control LED's Brightness

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
Control LED's brightness
/* Code generated by RoboBlockly v2.1 */
/* Problem Statement: 
    Control the LED's brightness using pot. The ration between
    LED's value and Pot values are potVal/1023*255 = LED's
    value.
    */
#include <arduino.h>
#include <stdbool.h>
double LEDpin;
int potPin;
double potVal;
double LEDval;

// Declare variables for pin assignments
// to hold values from the potemtiometer
// and hold values to be written to the LED
LEDpin = 3;
potPin = A0;
potVal = 0;
LEDval = 0;
// Set the pin mode of the LED pin to output mode
pinMode(LEDpin, OUTPUT);
while(true) {
  // Get the current voltage across the potentiometer
  potVal = analogRead(potPin);
  // Calculate the output value using the ratio of the
  // Input value to its maximum and print it out
  LEDval = (double(potVal)/1023) * 255;
  // Write the output value to the LED pin
  analogWrite(LEDpin, LEDval);
}
Load Blocks
Hardware
LArduino
Workspace Show Ch Save File
Problem Statement:

Control the LED's brightness using Potentiometer. When you turn the potentiometer, the LED light will become brighter or dimmer.


		
Rubbish bin
Time