#!/bin/bash
# PODNAME: cheerlights
# ABSTRACT: make hypnocube respond to cheerlights

# to change global cheerlights colors
# http://www.cheerlights.com/control-cheerlights
# Example Tweet: @CheerLights Paint the town red

lastcolor=""
while true
do
  # let us know that things are still working
#  echo "clear black ; update" >>/tmp/hypnocube
#  sleep 0.5
  # fetch the cheelightss status and update the hypnocube
  color=`curl -s http://api.thingspeak.com/channels/1417/field/1/last.json | perl -ne '/.*?"field1":"(.*?)"/ ; print "$1";'`
  if [ "$color" != "$lastcolor" ] ; then
    date=`date`
    echo "$date : $color"
    lastcolor=$color
  fi
  cube "sphere $color;update\n" 
  # and give it a chance to change
  sleep 10
done

__END__

=pod

=encoding UTF-8

=head1 NAME

cheerlights - make hypnocube respond to cheerlights

=head1 VERSION

version 1.2

=head1 AUTHOR

Kevin Mulholland <moodfarm@cpan.org>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2014 by Kevin Mulholland.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

=cut
