pastebin - collaborative debugging tool
viktor.kpaste.net RSS


Untitled
Posted by Anonymous on Sat 10th Aug 2013 17:27
raw | new post

  1. // Public Domain 2013
  2. // by Viktor Criterion of SFAQT http://SuperFunAdventureQuestTime.com/
  3.  
  4. // An implementation of Asimov's three rules of roboitcs in Arduino/Wiring
  5.  
  6. //A robot may not injure a human being or, through inaction, allow a human being to come to harm.
  7. const int humanHarmPin =  8;      // if this pin goes high the action would harm a human.
  8. const int humanInDangerPin=9;      // if this pin goes high a human is in danger
  9.  
  10. //A robot must obey the orders given to it by human beings, except where such orders would conflict with the First Law.
  11. const int humanOrderPin=10; // if this pin goes high a human gave an order
  12.  
  13. //A robot must protect its own existence as long as such protection does not conflict with the First or Second Law.
  14. const int robotHarmPin=11; // if this pin goes high the action will harm self
  15.  
  16.  
  17. // Variables
  18. int humanPeril = LOW;             // ledState used to set the LED
  19. long previousMillis = 0;        // will store last time LED was updated
  20.  
  21. // the follow variables is a long because the time, measured in miliseconds,
  22. // will quickly become a bigger number than can be stored in an int.
  23. long interval = 1000;           // interval at which to blink (milliseconds)
  24.  
  25. void setup()
  26. {
  27.   // set the digital pin as output:
  28.   pinMode(humanHarmPin    ,INPUT);//requires external 10k pull down.
  29.   pinMode(humanInDangerPin,INPUT);//requires external 10k pull down.
  30.   pinMode(humanOrderPin   ,INPUT);//requires external 10k pull down.
  31.   pinMode(robotHarmPin    ,INPUT);//requires external 10k pull down.
  32. }
  33.  
  34. void loop()
  35. {
  36.   int actionAllowed=LOW; // default state is robot is not allowed to act
  37.   //check the state of the input pins.
  38.   int humanOrder   =digitalRead(humanOrderPin);
  39.   int humanInDanger=digitalRead(humanInDangerPin);
  40.   int humanHarm    =digitalRead(humanHarmPin);
  41.   int robotHarm    =digitalRead(robotHarmPin);
  42.  
  43.  
  44.   if (humanOrder==HIGH)
  45.   {
  46.     if (humanHarm==LOW) actionAllowed=HIGH;
  47.   }
  48.   if (robotHarm==HIGH)
  49.   {
  50.     if (humanOrder==HIGH && humanHarm==LOW) actionAllowed=HIGH;
  51.   }
  52.   if (humanInDanger==HIGH)
  53.   {
  54.     if (humanHarm==LOW) actionAllowed=HIGH;
  55.   }
  56.  
  57.  
  58.   if (actionAllowed==HIGH) doAction();
  59.  
  60. }
  61.  
  62. void doAction()
  63. {
  64.   //code goes here
  65. }

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.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}




All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at