Challenge reference to documentation


With reference to the Challenge problem for changing colours. I concluded that it was easy enough to use acceleration data that was being sampled and test their values against zero in order to set the colour values. This appeared to work correctly. However after having studied many distance courses mainly with the Open University here in UK I am aware that advice given in questions usually leads a student to a more efficient answer. I looked through the documentation and could not understand where I might have got a more efficient solution. What did i miss ?



Well, you know that the color must have three channels (RGB) that have values from 0-1. You know that the accelerometer can have values that are typically between -1 and 1 for three axes (XYZ).

You can, for example, say that red = (x + 1) / 2.0, green = (y + 1) / 2.0, etc., which would give you the appropriate value.

However, it is possible that the accelerometer will give you values greater than 1 or less than -1. So, you may want to push those values to within -1…1 and then normalize.