It's bin day!

Posted on
  • Putting the bins out is one of my chores, grumble grumble, but i always seem to forget when a bin day is, so as a programming kid i thought a calendar is too simple and boring so i broke out the Espruino and converted my bin dates to JSON. This script currently only checks if the specified date is a bin day and if it it prints what type of bin it is. I plan to use a RTC and a LCD to have this as a clock that can also show notifications, but i need to get a RTC for that (I've got some Chinese ones but there's no Espruino modules and i think they're broken anyway). When i add this all i'll need to do is get the RTC time and add a day (You put the bins out the night before) then either check when i update the clock part or every 10 or 30 mins.

    Currently to use just change the date variable to a string like "11/12/14" and press BTN1 or use check()

    var date = "5/6/14";
    
    
    var json = {"6/3/14":"g","13/3/14":"b","20/3/14":"g­","27/3/14":"b","3/4/14":"g","10/4/14":"­b","17/4/14":"g","25/4/14":"b","1/5/14":­"g","9/5/14":"b","15/5/14":"g","22/5/14"­:"b","30/5/14":"g","5/6/14":"b","12/6/14­":"g","19/6/14":"b","26/6/14":"g","3/7/1­4":"b","10/7/14":"g","17/7/14":"b","24/7­/14":"g","31/7/14":"b","7/8/14":"g","14/­8/14":"b","21/8/14":"g","29/8/14":"b","4­/9/14":"g","11/9/14":"b","18/9/14":"g","­25/9/14":"b","1/10/14":"g","9/10/14":"b"­,"16/10/14":"g","12/10/14":"b","30/10/14­":"g","6/11/14":"b","13/11/14":"g","20/1­1/14":"b","27/11/14":"g","4/12/14":"b","­11/12/14":"g","18/12/14":"b","24/12/14":­"g","2/1/15":"s","8/1/15":"g","15/1/15":­"b","22/1/15":"g","29/1/15":"b","5/2/15"­:"g","12/2/15":"b","19/2/15":"g","26/2/1­5":"b","5/3/15":"g","12/3/15":"b","19/3/­15":"g","26/3/15":"b","2/4/15":"g","10/4­/15":"b","16/4/15":"g","23/4/15":"b","30­/4/15":"g","8/5/15":"b","14/5/15":"g","2­1/5/15":"b","29/5/15":"g","4/6/15":"b","­11/6/15":"g","18/6/15":"b","25/6/15":"g"­,"2/7/15":"b","9/7/15":"g","16/7/15":"b"­,"23/7/15":"g","30/7/15":"b","6/8/15":"g­","13/8/15":"b","20/8/15":"g","27/8/15":­"b","4/9/15":"g","10/9/15":"b","17/9/15"­:"g","24/9/15":"b","1/10/15":"g","8/10/1­5":"b","15/10/15":"g","22/10/15":"b","29­/10/15":"g"};
    
    function check(){
      var type;
      if(!(date in json)){
        console.log("Not a bin day");
      }else{
        switch(json[date]) {
        case "g":
            type = "Green bin";
            break;
        case "b":
            type = "Brown bin";
            break;
        case "s":
            type = "Green & Plastic";
            break;
        }
        console.log("It's a bin day, its the " + type);
      }
    }
    
    setWatch(function(){check();}, BTN1, {repeat:true,edge:"rising", debounce:5/*ms*/});
    
  • I've just made a modification, more like a dirty little hack, to use clock module.

    var Clock = require("clock").Clock;
    var clk=new Clock(14,6,4,0,0,0,0); // Y,M,D H:M:S IDK,IDK
    
    var date;// = "5/6/14";
    
    var json = {"6/3/14":"g","13/3/14":"b","20/3/14":"g­","27/3/14":"b","3/4/14":"g","10/4/14":"­b","17/4/14":"g","25/4/14":"b","1/5/14":­"g","9/5/14":"b","15/5/14":"g","22/5/14"­:"b","30/5/14":"g","5/6/14":"b","12/6/14­":"g","19/6/14":"b","26/6/14":"g","3/7/1­4":"b","10/7/14":"g","17/7/14":"b","24/7­/14":"g","31/7/14":"b","7/8/14":"g","14/­8/14":"b","21/8/14":"g","29/8/14":"b","4­/9/14":"g","11/9/14":"b","18/9/14":"g","­25/9/14":"b","1/10/14":"g","9/10/14":"b"­,"16/10/14":"g","12/10/14":"b","30/10/14­":"g","6/11/14":"b","13/11/14":"g","20/1­1/14":"b","27/11/14":"g","4/12/14":"b","­11/12/14":"g","18/12/14":"b","24/12/14":­"g","2/1/15":"s","8/1/15":"g","15/1/15":­"b","22/1/15":"g","29/1/15":"b","5/2/15"­:"g","12/2/15":"b","19/2/15":"g","26/2/1­5":"b","5/3/15":"g","12/3/15":"b","19/3/­15":"g","26/3/15":"b","2/4/15":"g","10/4­/15":"b","16/4/15":"g","23/4/15":"b","30­/4/15":"g","8/5/15":"b","14/5/15":"g","2­1/5/15":"b","29/5/15":"g","4/6/15":"b","­11/6/15":"g","18/6/15":"b","25/6/15":"g"­,"2/7/15":"b","9/7/15":"g","16/7/15":"b"­,"23/7/15":"g","30/7/15":"b","6/8/15":"g­","13/8/15":"b","20/8/15":"g","27/8/15":­"b","4/9/15":"g","10/9/15":"b","17/9/15"­:"g","24/9/15":"b","1/10/15":"g","8/10/1­5":"b","15/10/15":"g","22/10/15":"b","29­/10/15":"g"};
    
    function check(){
      var type;
      if(!(date in json)){
        console.log("Not a bin day");
      }else{
        switch(json[date]) {
        case "g":
            type = "Green bin";
            break;
        case "b":
            type = "Brown bin";
            break;
        case "s":
            type = "Green & Plastic";
            break;
        }
        console.log("It's a bin day, its the " + type);
      }
    }
    
    function update(){
      var time = clk.getClockTime();
      
      date = Math.floor(time.day + 1) + "/" + time.month + "/" + time.year;
      
      check();
    }
    
    setWatch(function(){update();}, BTN1, {repeat:true,edge:"rising", debounce:5/*ms*/});
    //setInterval(update,10000);
    
  • Great... thanks! The clock module should work pretty well for this. I like the data/json structure too - it's easy to write and use, and in Espruino it's actually about as efficient as a standard integer-indexed array.

    Out of interest, is there a reason why you parsed the JSON string data, rather than just taking it out of the quotes and defining it like:

    var json = {"6/3/14":"g","13/3/14":"b","20/3/14":"g­","27/3/14":"b","3/4/14":"g","10/4/14":"­b","17/4/14":"g","25/4/14":"b","1/5/14":­"g","9/5/14":"b","15/5/14":"g","22/5/14"­:"b","30/5/14":"g","5/6/14":"b","12/6/14­":"g","19/6/14":"b","26/6/14":"g","3/7/1­4":"b","10/7/14":"g","17/7/14":"b","24/7­/14":"g","31/7/14":"b","7/8/14":"g","14/­8/14":"b","21/8/14":"g","29/8/14":"b","4­/9/14":"g","11/9/14":"b","18/9/14":"g","­25/9/14":"b","1/10/14":"g","9/10/14":"b"­,"16/10/14":"g","12/10/14":"b","30/10/14­":"g","6/11/14":"b","13/11/14":"g","20/1­1/14":"b","27/11/14":"g","4/12/14":"b","­11/12/14":"g","18/12/14":"b","24/12/14":­"g","2/1/15":"s","8/1/15":"g","15/1/15":­"b","22/1/15":"g","29/1/15":"b","5/2/15"­:"g","12/2/15":"b","19/2/15":"g","26/2/1­5":"b","5/3/15":"g","12/3/15":"b","19/3/­15":"g","26/3/15":"b","2/4/15":"g","10/4­/15":"b","16/4/15":"g","23/4/15":"b","30­/4/15":"g","8/5/15":"b","14/5/15":"g","2­1/5/15":"b","29/5/15":"g","4/6/15":"b","­11/6/15":"g","18/6/15":"b","25/6/15":"g"­,"2/7/15":"b","9/7/15":"g","16/7/15":"b"­,"23/7/15":"g","30/7/15":"b","6/8/15":"g­","13/8/15":"b","20/8/15":"g","27/8/15":­"b","4/9/15":"g","10/9/15":"b","17/9/15"­:"g","24/9/15":"b","1/10/15":"g","8/10/1­5":"b","15/10/15":"g","22/10/15":"b","29­/10/15":"g"};
    

    You could use one of the Nokia 5110 LCDs, or maybe even a Sharp Memory LCD - and then it could sit there running off a solar cell :)

    For this it may not be such a big deal, but Espruino's RTC uses the internal RC oscillator, which is only accurate to 1% or so. It's dead easy to solder on a watch crystal though.

  • The only reason the JSON was like that was that when i tried it i used [] not {}, woops.

    I plan to solder one of those crystals on but should i add some capacitors or are the traces truly enough?

  • The traces seem like enough - I think there is some capacitance inside the chip, as adding the capacitors you're supposed to often stops it from working!

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

It's bin day!

Posted by Avatar for MrTimcakes @MrTimcakes

Actions