Approved content

The content below is provided by a partner.

joy-it/Joy-Car 1.3.0 GitHub

This library provides a Microsoft Makecode package for the Joy-IT Joy-Car. See here for more details.

Initializing Joy-Car

You have to initialize the Joy-Car with your mainboard revision. You can find your revision on the backside of your mainboard. Older revisions than 1.2 have no revision number on the back. This will ensure that the repository is compatible with all revisions of the mainboard.

// Initialize Joy-Car with Mainboard revision 1.3 JoyCar.initJoyCar(RevisionMainboard.OnepThree)

Initializing the microcontroller you use

You have to initialize the microcontroller with which you use the Joy-Car. Therefore, you can use this library with the micro:bit and the Calliope.

// Initialize Joy-Car with the Calliope JoyCar.initController(ControllerType.Calliope)

Smart collision detection

The smart collision detection is only available if you have mounted the ultrasonic sensor in the top position, in combination with the servo motor. In this case, the ultrasonic sensor checks for obstacles in all front directions and returns if an obstacle is close or not.

Return value Direction
0 nothing
1 left
2 middle
3 right
// Start collision detection if (JoyCar.collisionDetection() == 1) { // do something }

Driving

You can drive the Joy-Car forwards or backwards by using the drive(...) block. Within this block you specify the direction aswell as the speed in percent from 0 to 100. Both motors will be driven in the selected direction with the selected speed.

// Move the Joy-Car forwards at 100% speed JoyCar.drive(FRDirection.Forward, 100) // Move the Joy-Car backwards at 40% speed JoyCar.drive(FRDirection.Reverse, 40) // Turn the Joy-Car left at 20% speed JoyCar.drive(FRLRDirection.Left, 20) // Turn the Joy-Car right at 60% speed JoyCar.drive(FRLRDirection.Right, 60)

Turning

You can use the turn(...) block to drive forwards or backwards in combination with turning left or right. You can specify the orientation (forward, reverse), direction (left, right) aswell as the speed (0 - 100%) and the size of the curve-radius (0-5). The larger the curve-radius the wider the turn will be (0 = very sharp turn, 5 = very wide turn).

// Turn forwards and left with 100% speed and a very sharp curve JoyCar.turn(FRDirection.Forward, LRDirection.Left, 100, 0) // Turn right and reverse with 50% speed and a wide curve JoyCar.turn(FRDirection.Reverse, LRDirection.Right, 50, 5)

Stopping

Use stop(...) to either brake with an intense stop or with declining speed.

// Intense Stop JoyCar.stop(StopIntensity.Intense) // Soft Stop JoyCar.stop(StopIntensity.Soft)

Servo Control

You can set the angle (0 - 180) of the two optional servos which are connected to pin P1 and P13 of the micro:bit by using servo(...).

// Set Servo 1 to 90 JoyCar.servo(1, 90) // Set Servo 2 to 45 JoyCar.servo(2, 45)

Bias

Both motors will probably, due to manufacturing tolerances, not spin at the very same speed. This can result in driving small curves when you intend to drive straight forward or backward. In this case you can set a global bias with bias(...) which will slow down the speed-signal for the specific motor. This shall compensate any speed differences.

// Reduce Left Motor Speed permanently by 5% JoyCar.bias(LRDirection.Left, 5) // Reduce Right Motor Speed permanently by 2% JoyCar.bias(LRDirection.Right, 2)

PWM-Signals

You can also send direct PWM-Signals to all four channels (Channel 2, Channel 3, Channel 4 & Channel 5) of the motor-controller by using drivePwm(...).

// Set PWM signal 255 to Channel 2 JoyCar.drivePwm(255, 0, 0, 0) // Set PWM signal 100 to Channel 3 JoyCar.drivePwm(0, 100, 0, 0) // Set PWM signal 255 to Channel 4 and 5 Joycar.drivePwm(0, 0, 255, 255)

Headlights

Turn on/off the headlights (white light from the two front LED modules) by using light(...).

// Turn on the headlights JoyCar.light(ToggleSwitch.On) // Turn off the headlights JoyCar.light(ToggleSwitch.Off)

Brakelights

Turn on/off the brakelight (red light from the two rear LED modules) by using brake(...).

// Turn on the brakelights JoyCar.brakelight(ToggleSwitch.On) // Turn off the brakelights JoyCar.brakelight(ToggleSwitch.Off)

Indicators

Turn on/off the indicators (flashing orange light from the front and rear LED module on the left or right side) for a specific side with indicator(...).

// Turn on the left indicators JoyCar.indicator(ToggleSwitch.On, SensorLRSelection.Left) // Turn off the right indicators JoyCar.indicator(ToggleSwitch.Off, SensorLRSelection.Right)

Hazard Lights

Turn on/off the hazard lights (flashing orange light from all LED modules) with hazardlights(...).

// Turn hazard lights on JoyCar.hazardlights(ToggleSwitch.On) // Turn hazard lights off JoyCar.hazardlights(ToggleSwitch.Off)

Reverse Lights

Turn on/off the reverse lights (white light from the rear LED modules) with reversinglight(...).

// Turn on reverse lights JoyCar.reversinglight(ToggleSwitch.On) // Turn off reverse lights JoyCar.reversinglight(ToggleSwitch.Off)

Ultrasonic Sensor

Check the ultrasonic sensor with sonar(). The return value is the distance to the closest object measured from the sensor. The sensor is connected to the pins P12 (echo) and P8 (trigger) of the micro:bit.

// Measure distance JoyCar.sonar()

Linefinder Sensor

Check the linefinder sensors with linefinder(...). The function returns true if a line was detected. The sensors are connected to channel 3, 4 & 5 of the IO-Expander.

// Check the left Linefinder Sensor JoyCar.linefinder(SensorLCRSelection.Left) // Check the center Linefinder Sensor JoyCar.linefinder(SensorLCRSelection.Center) // Check the right Linefinder Sensor JoyCar.linefinder(SensorLCRSelection.Right)

Obstacle Sensor

Check the obstacle sensors with obstacleavoidance(...). The function returns true if an obstacle was detected. The sensors are connected to channel 1 & 2 of the IO-Expander.

// Check left obstacle sensor JoyCar.obstacleavoidance(SensorLRSelection.Left) // Check right obstacle sensor JoyCar.obstacleavoidance(SensorLRSelection.Right)

Speed Sensor

Check the speed sensors with speed(...). The function returns true if the light is interrupted by the perforated disc on the motor.

// Check left speed sensor JoyCar.speed(SensorLRSelection.Left) // Check right speed sensor JoyCar.speed(SensorLRSelection.Right)

Buzzer

Play predefined sound with buzzer for a certain amount of microseconds with buzzer_sound().

// Play the C for 1 second JoyCar.buzzer_sound(Note.C, 1000)

Play predefined melodies with the buzzer with buzzer_melody(). You can also specifiy repeat options.

// Play the Dadadadum Sound once JoyCar.buzzer_melody(Melodies.Dadadadum, MelodyOptions.Once) // Play the Nyan Sound on repeat JoyCar.buzzer_melody(Melodies.Nyan, MelodyOptions.Forever)

Read Battery Voltage

Read the current battery voltage from the ADC on the AnalogPin2 by using readAdc().

// Print battery voltage to console serial.writeString(JoyCar.readAdc());

Read IO Expander

Read values from IO expander with readIOExpander().

// Print values from IO expander to console serial.writeString(JoyCar.readIOExpander());

Write IO Expander

Write values on the free pins from the IO expander with writeIOExpander(). You can write on pin 7 or with revision 1.3 or newer also on pin 0 and pin 1.

// Set pin 7 from the IO expander high JoyCar.writeIOExpander(IOExpanderPin.Pin7, 1); // Set pin 1 from the IO expander low (only possible with Rev 1.3 or newer) JoyCar.writeIOExpander(IOExpanderPin.Pin1, 0);

Supported targets

License

MIT