{"id":228,"date":"2015-11-04T21:00:25","date_gmt":"2015-11-04T21:00:25","guid":{"rendered":"http:\/\/dronesonen.hibu.no\/?p=228"},"modified":"2015-11-04T08:50:30","modified_gmt":"2015-11-04T08:50:30","slug":"kode-til-bilene","status":"publish","type":"post","link":"https:\/\/dronesonen.usn.no\/?p=228","title":{"rendered":"Kode til bilene 1"},"content":{"rendered":"<p>#include &lt;Servo.h&gt;<\/p>\n<p>const int MotorA_IA = 2;<br \/>\nconst int MotorA_IB = 3; \/\/PWM<br \/>\nconst int MotorB_IA = 4;<br \/>\nconst int MotorB_IB = 5; \/\/PWM<\/p>\n<p>const int Motor2A_IA = 6;<br \/>\nconst int Motor2A_IB = 7; \/\/PWM<br \/>\nconst int Motor2B_IA = 8;<br \/>\nconst int Motor2B_IB = 9;\/\/PWM<\/p>\n<p>const int KOMMUNIKASJON= 12;<\/p>\n<p>const int MOTOR1 = 1;<br \/>\nconst int MOTOR2 = 2;<br \/>\nconst int MOTOR3 = 3;<br \/>\nconst int MOTOR4 = 4;<\/p>\n<p>const int ServoPin = 10;<br \/>\nServo MYSERVO;<\/p>\n<p>const int TRIGPIN = 11;<br \/>\nconst int ECHOPIN = 12;<\/p>\n<p>void drive(int Motor,int Speed)<br \/>\n{<br \/>\nint MotorPinA = MotorA_IA;<br \/>\nint MotorPinB = MotorA_IB;<\/p>\n<p>if (Speed &gt; 255 || Speed &lt; -255)<br \/>\nSpeed = 0;<\/p>\n<p>Speed *= -1;<\/p>\n<p>switch (Motor)<br \/>\n{<br \/>\ncase MOTOR1:<br \/>\nMotorPinA = MotorA_IA;<br \/>\nMotorPinB = MotorA_IB;<br \/>\nbreak;<br \/>\ncase MOTOR2:<br \/>\nMotorPinA = MotorB_IA;<br \/>\nMotorPinB = MotorB_IB;<br \/>\nbreak;<br \/>\ncase MOTOR3:<br \/>\nMotorPinA = Motor2A_IA;<br \/>\nMotorPinB = Motor2A_IB;<br \/>\nbreak;<br \/>\ncase MOTOR4:<br \/>\nMotorPinA = Motor2B_IA;<br \/>\nMotorPinB = Motor2B_IB;<br \/>\nbreak;<br \/>\n}<\/p>\n<p>if (Speed &gt;= 0)<br \/>\n{<br \/>\ndigitalWrite(MotorPinA, 0);<br \/>\nanalogWrite(MotorPinB, Speed);<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\ndigitalWrite(MotorPinA, 1);<br \/>\nanalogWrite(MotorPinB, 255+Speed);<br \/>\n}<br \/>\n}<\/p>\n<p>long ping(){<br \/>\nlong duration;<br \/>\ndigitalWrite(TRIGPIN, LOW);<br \/>\ndelayMicroseconds(2);<br \/>\ndigitalWrite(TRIGPIN, HIGH);<br \/>\ndelayMicroseconds(10);<br \/>\ndigitalWrite(TRIGPIN, LOW);<br \/>\nduration = pulseIn(ECHOPIN, HIGH);<br \/>\nreturn duration;<br \/>\n}<\/p>\n<p>void direction(int pos){<br \/>\nMYSERVO.write(pos);<br \/>\n}<\/p>\n<p>void setup()<br \/>\n{<br \/>\nSerial.begin(9600);<br \/>\npinMode(MotorA_IA, OUTPUT);<br \/>\npinMode(MotorA_IB, OUTPUT);<br \/>\npinMode(MotorB_IA, OUTPUT);<br \/>\npinMode(MotorB_IB, OUTPUT);<br \/>\npinMode(Motor2A_IA, OUTPUT);<br \/>\npinMode(Motor2A_IB, OUTPUT);<br \/>\npinMode(Motor2B_IA, OUTPUT);<br \/>\npinMode(Motor2B_IA, OUTPUT);<\/p>\n<p>pinMode(KOMMUNIKASJON, OUTPUT);<\/p>\n<p>pinMode(ServoPin, OUTPUT);<br \/>\nMYSERVO.attach(ServoPin);<\/p>\n<p>pinMode(TRIGPIN, OUTPUT);<br \/>\npinMode(ECHOPIN, INPUT);<br \/>\n}<\/p>\n<p>void loop()<br \/>\n{<br \/>\n\/\/Her skal koden deres st\u00e5<br \/>\n}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>#include &lt;Servo.h&gt; const int MotorA_IA = 2; const int MotorA_IB = 3; \/\/PWM const int MotorB_IA = 4; const int MotorB_IB = 5; \/\/PWM const int Motor2A_IA = 6; const int Motor2A_IB = 7; \/\/PWM const int Motor2B_IA = 8; const int Motor2B_IB = 9;\/\/PWM const int KOMMUNIKASJON= 12; const int MOTOR1 = 1; const [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-228","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/dronesonen.usn.no\/index.php?rest_route=\/wp\/v2\/posts\/228","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dronesonen.usn.no\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dronesonen.usn.no\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dronesonen.usn.no\/index.php?rest_route=\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/dronesonen.usn.no\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=228"}],"version-history":[{"count":5,"href":"https:\/\/dronesonen.usn.no\/index.php?rest_route=\/wp\/v2\/posts\/228\/revisions"}],"predecessor-version":[{"id":1161,"href":"https:\/\/dronesonen.usn.no\/index.php?rest_route=\/wp\/v2\/posts\/228\/revisions\/1161"}],"wp:attachment":[{"href":"https:\/\/dronesonen.usn.no\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=228"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dronesonen.usn.no\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=228"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dronesonen.usn.no\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=228"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}