- // Public Domain 2013
- // by Viktor Criterion of SFAQT http://SuperFunAdventureQuestTime.com/
- // An implementation of Asimov's three rules of roboitcs in Arduino/Wiring
- //A robot may not injure a human being or, through inaction, allow a human being to come to harm.
- const int humanHarmPin = 8; // if this pin goes high the action would harm a human.
- const int humanInDangerPin=9; // if this pin goes high a human is in danger
- //A robot must obey the orders given to it by human beings, except where such orders would conflict with the First Law.
- const int humanOrderPin=10; // if this pin goes high a human gave an order
- //A robot must protect its own existence as long as such protection does not conflict with the First or Second Law.
- const int robotHarmPin=11; // if this pin goes high the action will harm self
- // Variables
- int humanPeril = LOW; // ledState used to set the LED
- long previousMillis = 0; // will store last time LED was updated
- // the follow variables is a long because the time, measured in miliseconds,
- // will quickly become a bigger number than can be stored in an int.
- long interval = 1000; // interval at which to blink (milliseconds)
- void setup()
- {
- // set the digital pin as output:
- pinMode(humanHarmPin ,INPUT);//requires external 10k pull down.
- pinMode(humanInDangerPin,INPUT);//requires external 10k pull down.
- pinMode(humanOrderPin ,INPUT);//requires external 10k pull down.
- pinMode(robotHarmPin ,INPUT);//requires external 10k pull down.
- }
- void loop()
- {
- int actionAllowed=LOW; // default state is robot is not allowed to act
- //check the state of the input pins.
- int humanOrder =digitalRead(humanOrderPin);
- int humanInDanger=digitalRead(humanInDangerPin);
- int humanHarm =digitalRead(humanHarmPin);
- int robotHarm =digitalRead(robotHarmPin);
- if (humanOrder==HIGH)
- {
- if (humanHarm==LOW) actionAllowed=HIGH;
- }
- if (robotHarm==HIGH)
- {
- if (humanOrder==HIGH && humanHarm==LOW) actionAllowed=HIGH;
- }
- if (humanInDanger==HIGH)
- {
- if (humanHarm==LOW) actionAllowed=HIGH;
- }
- if (actionAllowed==HIGH) doAction();
- }
- void doAction()
- {
- //code goes here
- }
Untitled
Posted by Anonymous on Sat 10th Aug 2013 17:27
raw | new post
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.