/*var sensor = require("HC-SR04").connect(C6,C7,function(dist) { console.log(dist+" cm away"); }); setInterval(function() { sensor.trigger(); // send pulse }, 500); */ LCD.clear(); SPI2.setup({baud:3200000, mosi:B15}); var rgb = new Uint8Array(50*3); // var xi = 6, xd = xi - 1; // var pos=0; function lightsOff() { clearInterval(cycle); pos++; for (var i=0;i<rgb.length;i+=3) { rgb[i ] = 0; rgb[i+1] = 0; rgb[i+2] = 0; } SPI2.send4bit(rgb, 0b0001, 0b0011); } var patterns = []; //patterns.push(lightsOff); patterns.push(function() { // Fading white lights pos++; for (var i=0;i<rgb.length;i+=3) { var col = (Math.sin(i+pos*0.2)+1) * 127; rgb[i ] = col; rgb[i+1] = col; rgb[i+2] = col; } }); patterns.push(function() { // Fading Red lights pos++; for (var i=0;i<rgb.length;i+=3) { var col = (Math.sin(i+pos*0.2)+1) * 127; rgb[i ] = col; rgb[i+1] = 0; rgb[i+2] = 0; } }); patterns.push(function() { // Fading Green lights pos++; for (var i=0;i<rgb.length;i+=3) { var col = (Math.sin(i+pos*0.2)+1) * 127; rgb[i ] = 0; rgb[i+1] = col; rgb[i+2] = 0; } }); patterns.push(function() { // Fading Blue lights pos++; for (var i=0;i<rgb.length;i+=3) { var col = (Math.sin(i+pos*0.2)+1) * 127; rgb[i ] = 0; rgb[i+1] = 0; rgb[i+2] = col; } }); patterns.push(function() { // Low red light pos++; for (var i=0;i<rgb.length;i+=3) { var col = 85; rgb[i ] = col; rgb[i+1] = 0; rgb[i+2] = 0; } }); patterns.push(function() { // Medium red light pos++; for (var i=0;i<rgb.length;i+=3) { var col = 170; rgb[i ] = col; rgb[i+1] = 0; rgb[i+2] = 0; } }); patterns.push(function() { // Full red light 2 pos++; for (var i=0;i<rgb.length;i+=3) { var col = 255; rgb[i ] = col; rgb[i+1] = 0; rgb[i+2] = 0; } }); patterns.push(function() { // low blue light pos++; for (var i=0;i<rgb.length;i+=3) { var col = 85; rgb[i ] = 0; rgb[i+1] = 0; rgb[i+2] = col; } }); patterns.push(function() { // Med blue light pos++; for (var i=0;i<rgb.length;i+=3) { var col = 170; rgb[i ] = 0; rgb[i+1] = 0; rgb[i+2] = col; } }); patterns.push(function() { // Full blue light pos++; for (var i=0;i<rgb.length;i+=3) { var col = 255; rgb[i ] = 0; rgb[i+1] = 0; rgb[i+2] = col; } }); patterns.push(function() { // low Green light pos++; for (var i=0;i<rgb.length;i+=3) { var col = 85; rgb[i ] = 0; rgb[i+1] = col; rgb[i+2] = 0; } }); patterns.push(function() { // Med Green light pos++; for (var i=0;i<rgb.length;i+=3) { var col = 170; rgb[i ] = 0; rgb[i+1] = col; rgb[i+2] = 0; } }); patterns.push(function() { // Full Green light pos++; for (var i=0;i<rgb.length;i+=3) { var col = 255; rgb[i ] = 0; rgb[i+1] = col; rgb[i+2] = 0; } }); patterns.push(function() { // Fading colours pos++; for (var i=0;i<rgb.length;i+=3) { rgb[i ] = (1 + Math.sin((i+pos)*0.1324)) * 127; rgb[i+1] = (1 + Math.sin((i+pos)*0.1654)) * 127; rgb[i+2] = (1 + Math.sin((i+pos)*0.1)) * 127; } }); patterns.push(function() { // Random White lights for (var i=0;i<rgb.length;i+=3) { rgb[i ] = Math.random()*255; rgb[i+1] = Math.random()*255; rgb[i+2] = Math.random()*255; } }); patterns.push(function() { // Random Red lights for (var i=0;i<rgb.length;i+=3) { rgb[i ] = Math.random()*255; rgb[i+1] = 0; rgb[i+2] = 0; } }); patterns.push(function() { // Random Green lights for (var i=0;i<rgb.length;i+=3) { rgb[i ] = 0; rgb[i+1] = Math.random()*255; rgb[i+2] = 0; } }); patterns.push(function() { // Random Blue lights for (var i=0;i<rgb.length;i+=3) { rgb[i ] = 0; rgb[i+1] = 0; rgb[i+2] = Math.random()*255; } }); var getPattern = patterns[0]; function doLights() { //getPattern(); // var xi = 6, xd = xi - 1; LCD.fillRect(x,0,x+xd,240); x += xi; // for (var i=0;i<rgb.length;i+=3) { LCD.setColor(rgb[i+0]/256,rgb[i+1]/256,rgb[i+2]/256); LCD.fillRect(i,0,i+2,240); } SPI2.send4bit(rgb, 0b0001, 0b0011); } var patternNumber = 0; function changePattern() { patternNumber = (patternNumber+1) % patterns.length; getPattern = patterns[patternNumber]; } setWatch(changePattern, BTN, { repeat: true, edge:'rising', debounce: 50 }); cycle = setInterval(doLights,50);
The first set of changes showed nothing on the screen.
1 Attachment
@GarrettL started
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
The first set of changes showed nothing on the screen.
1 Attachment