Color Rings with Photon
https://makecode.com/_2Rbiqv2juUCo
Temperature ring
https://makecode.com/_bMsCpiAH7V44
NeoPixel Colors
https://github.com/Microsoft/pxt-adafruit/blob/master/docs/reference/light/set-photon-pen-hue.md
Programs
Temperature NeoPixel Ring with Alarm
let item = 0
forever(function () {
// Check switch
console.log('running');
input.onSwitchMoved(SwitchDirection.Left, function () {
// activate motion detector
});
const positionIsRight = input.switchRight();
if (positionIsRight) {
const initialLightValue = input.lightLevel();
pause(1000)
const currentLightValue = input.lightLevel();
const difference = initialLightValue - currentLightValue;
if (difference > 5) {
forever(() => {
light.showRing(
`white white white white white white white white white white`
)
pause(100)
light.showRing(
`black black black black black black black black black black`
)
pause(100)
})
}
// Light detector
} else {
input.buttonA.onEvent(ButtonEvent.Click, function () {
light.setBrightness(255);
})
input.buttonB.onEvent(ButtonEvent.Click, function () {
light.setBrightness(20);
})
let color = 191;
const temperature = input.temperature(TemperatureUnit.Celsius);
if (temperature <= 20) color = 170;
if (temperature > 20 && temperature <= 25) color = 86;
if (temperature > 25 && temperature <= 27) color = 29;
if (temperature >= 28) color = 255;
light.setPhotonMode(PhotonMode.PenDown)
for (let i = 0; i < 9; i++) {
light.photonForward(1)
light.setPhotonPenHue(color)
pause(100)
}
}
})
Temperature Blinker
forever(() => {
let color = "white";
const temperature = input.temperature(TemperatureUnit.Celsius);
if (temperature <= 20) color = "blue";
if (temperature > 20 && temperature <= 25) color = "green";
if (temperature > 25 && temperature <= 27) color = "yellow";
if (temperature >= 28) color = "red";
console.log(${temperature} ${color})
light.clear();
pause(1000)
light.showRing(${color} ${color} ${color} ${color} ${color} ${color} ${color} ${color} ${color} ${color})
})
Timer Clock
forever(() => { // Turn all neo pixels for (let p = 0; p < 10; p++) { light.setPixelColor(p, 0x00FFFF); }
// Compute time (5sec timer)
const delayTime = 5000 / 10;
// Change colors
for (let p = 0; p < 10; p++) {
loops.pause(delayTime);
light.setPixelColor(p, 0x000000);
if (p === 9) {
loops.pause(5000);
}
}
})
Timer and Thermometer
let item = 0; let hour = 5; //sec
const scanAndSetTemperatureColor = () => { let color = "white"; const temperature = input.temperature(TemperatureUnit.Celsius); if (temperature <= 20) color = "blue"; if (temperature > 20 && temperature <= 24) color = "green"; if (temperature > 24 && temperature <= 27) color = "orange"; if (temperature >= 28) color = "red"; floodRing(color);
}
const floodRing = (color: string) => {
light.showRing(${color} ${color} ${color} ${color} ${color} ${color} ${color} ${color} ${color} ${color})
}
const resetClock = () => { hour = 3600; light.setPhotonMode(PhotonMode.Off); };
const showNeoPixelPhoton = () => { while (hour === 0) { light.setPhotonMode(PhotonMode.PenDown) for (let i = 0; i < 9; i++) { light.photonForward(1) light.setPhotonPenHue(122) pause(100) } } };
forever(function () {
// Check switch
console.log('running');
input.onSwitchMoved(SwitchDirection.Left, function () {
// activate motion detector
});
const positionIsRight = input.switchRight();
if (positionIsRight) {
const initialLightValue = input.lightLevel();
pause(1000)
const currentLightValue = input.lightLevel();
const difference = initialLightValue - currentLightValue;
if (difference > 5) {
forever(() => {
light.showRing(
white white white white white white white white white white
)
pause(100)
light.showRing(
black black black black black black black black black black
)
pause(100)
})
}
} else {
// Brightness
input.buttonA.onEvent(ButtonEvent.Click, function () {
light.setBrightness(255);
resetClock();
})
input.buttonB.onEvent(ButtonEvent.Click, function () {
light.setBrightness(20);
resetClock();
})
// Thermometer
scanAndSetTemperatureColor();
// Timer (1 hour)
loops.pause(1000); //sec
hour -= (1);
console.log(`hour, ${hour}`);
scanAndSetTemperatureColor();
if (hour === 0) {
floodRing("white");
light.setBrightness(255);
showNeoPixelPhoton();
loops.pause(60000); // alarm for 1mins
resetClock();
}
}
})
Created on 4/1/2019