SHARE
TWEET

wadea33

a guest Apr 21st, 2017 50 in 20 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <SoftwareSerial.h>
  2.  SoftwareSerial myserial(5, 6);
  3.  int led = 11;
  4.  int led2 = 12;
  5. int led3 = 13;
  6. int counter = 0;
  7.  int i = 0;
  8. void intrptFunction() {
  9. for (int i = 0; i < 100; i++)
  10.  delayMicroseconds(1000); }
  11. void setup() {
  12. myserial.begin(9600); pinMode(3, INPUT_PULLUP);
  13. attachInterrupt (digitalPinToInterrupt(3), add , CHANGE); pinMode(led, OUTPUT);
  14. pinMode(led2, OUTPUT);
  15. pinMode(led3, OUTPUT); }
  16.  void loop() {
  17. if (myserial.available()) {
  18.  if (myserial.read() == 'm')
  19. {
  20.  digitalWrite(led , HIGH);
  21.  digitalWrite(led2 , HIGH);
  22. digitalWrite(led3 , HIGH);
  23.  switch (counter) {
  24. case 5: goRight();
  25. break;
  26. case 7: goLeft();
  27.  break;
  28. case 9: goRight();
  29.  break;
  30. case 11: counter = 0;
  31. break;
  32.  }
  33. }
  34.  if (myserial.read() == 'w') { // الامر الثاني digitalWrite(led , HIGH);
  35. digitalWrite(led2 , HIGH);
  36. digitalWrite(led3 , HIGH);
  37. switch (counter) {
  38.  case 5: goLeft();
  39. break;
  40. case 7: goRight();
  41.  break;
  42. case 9: goLeft();
  43. break;
  44. case 11: counter = 0;
  45.  break;
  46.  }
  47. }
  48. }
  49. }
  50. void goRight() {
  51.  digitalWrite(led , LOW);
  52.  digitalWrite(led2 , HIGH);
  53. digitalWrite(led3 , LOW);
  54. delay(1000);
  55. digitalWrite(led , HIGH);
  56. digitalWrite(led3 , HIGH); }
  57.  
  58.  void goLeft() {
  59.  digitalWrite(led , HIGH);
  60. digitalWrite(led2 , LOW);
  61. digitalWrite(led3 , LOW);
  62. delay(1000);
  63. digitalWrite(led2 , HIGH);
  64. digitalWrite(led3 , HIGH); }
  65.  
  66.  void add() {
  67.  counter++;
  68.  
  69.     }
RAW Paste Data
Top