• Software:

    var rh=-1;
    var t=-1;
    var statusview=1;
    var menustate=0;
    var menuopt=0;
    var inval="";
    var colors=["BLUE","COOL","WARM","YELL","PINK"];
    var ledstate=[0.4,1,0.8,0,0.2];
    var presets=[[0.9,1,0.6,0,0],[0,0.6,1,0.8,0.4],[0.5,0.5,0.5,0.5,0.5]];
    var prenames=["COLD\nWHIT","VERY\nWARM","HALF\nHALF"];
    var menu=[0,4,presets.length+1];
    var ledpins=[C6,C9,C8,A2,C7];
    var gw=new Uint8Array([5,7,7,5,5]);
    var kp=require("KeyPad").connect([C12,C15,C0,C1],[C2,C3,A0,A1], function(e) {onKey(e);});
    require("Font8x12").add(Graphics);
    
    function onKey(e){  //sdfsdfsdf
    	var k="123A456B789C*0#D"[e];
    	if (e==12){
    		if (menustate==3){
    			menustate=0;
    		} else {
    			menustate++;
    		}
    		menuopt=0;
    		inval="";
    		uplcd();
    	} else if (e==14 && menustate) {
    		if (menustate==1 && inval) {
    			var v=E.clip(parseInt(inval),0,100);
    			v=v/100;
    			ledstate[menuopt]=v;
    			inval="";
    			uplcd();
    			upled();
    		} else if (menustate==2 && menuopt) {
    			ledstate=presets[menuopt-1];
    			menuopt=0;
    			menustate=0;
    			uplcd();
    			upled();
    		}
    	} else if (e==3 && menustate) {
    		if (menuopt>=menu[menustate]) {
    			menuopt=0;
    		} else {
    			menuopt++;
    		}
    		inval="";
    		uplcd();
    	} else if ((e&0x03)==3) {
    		console.log(k);
    	} else if (menustate==1) {
    		if (inval.length < 3) {
    			inval=inval+k;
    		} else {
    			inval="";
    		}
    		uplcd();
    	}
    
    	g.backlighton();
    }
    
    digitalWrite(A13,0);
    var g=require("PCD8544").connect(SPI2,C4,C5,B1, function() {
            g.clear();
            g.setFont8x12();
            g.drawString("LCD OK",0,0);
            g.flip();
            g.setContrast(0.45);
            g.bktim=0;
            setTimeout("g.backlighton();",1000);
    });
    
    g.backlighton = function() {
    	digitalWrite(B0,1);
    	if (this.bktim) {
    		clearTimeout(this.bktim);
    		this.bktim=0;
    	}
    	this.bktim=setTimeout("digitalWrite(B0,0);g.bktim=0;",5000);
    };
    
    
    var e=require("DHT22").connect(A6);
    
    setInterval("e.read(function(a){rh=a.rh;t=a.temp;});",30000);
    
    setTimeout("setInterval(function(){uplcd();},30000)",15000);
    
    function uplcd() {
    	g.clear();
    	g.setFont8x12();
    	g.drawString(t.toFixed(1)+" C "+rh.toFixed(1)+"%",0,0);
    	if (menustate < 3) {
    		var vals=ledstate.slice(0);
    		if (menustate==2 && menuopt){
    			vals=presets[menuopt-1];
    		} else if (menustate==1 && inval) {
    			vals[menuopt]=(parseInt(inval)/100);
    		}
    		var x=3;
    		for (var i=0;i<5;i++) {
    			var nx=x+gw[i];
    			g.drawRect(x,14,nx,39);
    			g.fillRect(x,(39-ledstate[i]*25),nx,39);
    			if (vals[i] != ledstate[i] ) {
    				if (vals[i] > ledstate[i]) {
    					g.fillRect(x+1,(39-vals[i]*25),nx-1,40-vals[i]*25);
    				} else {
    					g.setColor(0);
    					g.fillRect(x+1,(39-vals[i]*25),nx-1,38-vals[i]*25);
    					g.setColor(1);
    				}
    			}
    			x=nx+4;
    		}
    		g.setColor(1);
    		g.setFontBitmap();
    		g.drawString("B",4,41);
    		g.drawString("C",14,41);
    		g.drawString("W",25,41);
    		g.drawString("Y",35,41);
    		g.drawString("P",44,41);
    	}
    	if (menustate==1) {
    		g.setFont8x12();
    		g.drawString(colors[menuopt],52,13);
    		g.drawString((100*ledstate[menuopt]).toFixed(),60,24);
    		if (inval) {
    			g.drawString(inval,60,35);
    		}
    	} else if (menustate==2) {
    		g.setFont8x12();
    		if (menuopt) {
    			g.drawString(prenames[menuopt-1],52,13);
    		} else {
    			g.drawString("LOAD",52,13);
    		}
    	}
    	g.flip();
    }
    
    function upled() {
    	for (var i=0;i<5;i++) {
    		analogWrite(ledpins[i],ledstate[i]);
    	}
    }
    
    
About

Avatar for DrAzzy @DrAzzy started