Last active
August 29, 2015 14:11
-
-
Save assertchris/485d41120700d2ac3ec6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
interface Action | |
{ | |
public function matches(array $message); | |
public function handle($inbox, array $message); | |
} | |
class TwitterAction implements Action | |
{ | |
public function matches(array $message) | |
{ | |
return stristr($message["from"], "@twitter.com"); | |
} | |
public function handle($inbox, array $message) | |
{ | |
echo "Twitter: " . $message["subject"] . "\n"; | |
// imap_setflag_full($inbox, "{$id}", "\\Seen"); | |
} | |
} | |
class FacebookAction implements Action | |
{ | |
public function matches(array $message) | |
{ | |
return stristr($message["from"], "@facebookmail.com"); | |
} | |
public function handle($inbox, array $message) | |
{ | |
echo "Facebook: " . $message["subject"] . "\n"; | |
// imap_setflag_full($inbox, "{$id}", "\\Seen"); | |
} | |
} | |
class TravisAction implements Action | |
{ | |
public function matches(array $message) | |
{ | |
return stristr($message["from"], "@travis-ci.org"); | |
} | |
public function handle($inbox, array $message) | |
{ | |
echo "Travis: " . $message["subject"] . "\n"; | |
// imap_setflag_full($inbox, "{$id}", "\\Seen"); | |
} | |
} | |
$actions = [ | |
new TwitterAction(), | |
new FacebookAction() | |
]; | |
$hostname = "{imap.gmail.com:993/imap/ssl}INBOX"; | |
$username = "[email protected]"; | |
$password = "example"; | |
$inbox = imap_open($hostname, $username, $password) or die("Cannot connect to Gmail: " . imap_last_error()); | |
$emails = imap_search($inbox, "UNSEEN"); | |
if ($emails) { | |
foreach ($emails as $id) { | |
$message = imap_fetch_overview($inbox, $id, 0); | |
foreach ($actions as $action) { | |
if ($action->matches((array) $message[0])) { | |
$action->handle($inbox, (array) $message[0]); | |
break; | |
} | |
} | |
} | |
} | |
imap_close($inbox); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require("vendor/autoload.php"); | |
$device = new PHPMake\Firmata\Device("/dev/tty.usbserial-A7030YFN"); | |
$device->setPinMode(10, PHPMake\Firmata::PWM); | |
// $device->setPinMode(10, PHPMake\Firmata::PWM); | |
// $device->setPinMode(11, PHPMake\Firmata::PWM); | |
$device->analogWrite(10, 255); | |
// for ($i = 0; $i < 3; ++$i) { | |
// $device->analogWrite(9, 0); | |
// $device->analogWrite(10, 255); | |
// $device->analogWrite(11, 255); | |
// sleep(1); | |
// $device->analogWrite(9, 0); | |
// $device->analogWrite(10, 0); | |
// $device->analogWrite(11, 0); | |
// sleep(1); | |
// } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "assertchris/blinkie", | |
"license": "MIT", | |
"authors": [ | |
{ | |
"name": "Christopher Pitt", | |
"email": "[email protected]" | |
} | |
], | |
"minimum-stability": "dev", | |
"require": { | |
"phpmake/firmata": "dev-master" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment