R2D2 by Sphero Playground - Lights Lesson

In the Lights lesson I run into an error when trying to set the brightness of the

LogicDisplaysLED or the HoloProjectorLED.


Whenever I use the

- setLogicDisplayLeds(brightness: 255)

- setHoloProjectorLed(brightness: 255)

commands, R2D2 just beeps and shakes its head.


Did anyone manage to finish this lesson successfully?


This is the code I came up with:


func flashLights(){

setLogicDisplayLeds(brightness: 255)

setHoloProjectorLed(brightness: 255)

wait(for: 1)

setLogicDisplayLeds(brightness: 0)

setHoloProjectorLed(brightness: 0)

wait(for: 1)

}

func startMessage() {

for i in 1 ... 5 {

flashLights()

}

}

Problem solved:

The Lights exercise not only requires you to do things in a specific order, it also requires LogicDisplayLED and HoloProjecrtorLED to be switched on and off at the same time with a wait in between.


This is the working code:


func startMessage() {

setFrontPSILed(color: FrontPSIColor.blue)

setBackPSILed(color: BackPSIColor.yellow)

play(sound: R2D2Sound.talking)

for index in 1 ... 5 {

flashLights()

}

}


func flashLights() {

setLogicDisplayLeds(brightness: 255)

setHoloProjectorLed(brightness: 255)

wait(for: 1)

setHoloProjectorLed(brightness: 0)

setLogicDisplayLeds(brightness: 0)

wait(for: 1)

}


And a version that’s a little bit more sophisticated:

let off=0

let on=255

let iterations=51


func startMessage() {

setFrontPSILed(color: FrontPSIColor.blue)

setBackPSILed(color: BackPSIColor.yellow)

play(sound: R2D2Sound.talking)

for index in 1 ... iterations {

flashLights(index, iterations)

}

}


func flashLights(_ index: Int,_ iterations: Int) {

let delay=0.01

setLogicDisplayLeds(brightness: (index*on/iterations))

setHoloProjectorLed(brightness:(index*on/iterations))

wait(for: delay)

setHoloProjectorLed(brightness:off)

setLogicDisplayLeds(brightness:off)

wait(for: delay)

}

I started a command reference for the Sphero R2D2 Swift Playground.

In case you are interested it can be found at: https://github.com/BitsDream/R2D2-Playground

Hi, sorry to resurrect a dead thread.


I'm getting a Sphero R2-D2 and I've updated to the latest version of Swift Playgrounds, but the R2-D2 by Sphero Playground is no longer there.


I contacted Sphero and this is what they said:


The R2D2 playground is no longer supported after the recent Swift upgrade.

At this time, we're choosing not to support an updated version.


If you still have a copy and willing to share it, I would be most grateful. Swapping the chapters with the latest Sphero template as suggested by AaronZ in another thread should work.


Any help is most appreciated.


Thank you.

R2D2 by Sphero Playground - Lights Lesson
 
 
Q