Arduino Serial Functionaccountnew

broken image


Serial: serial port object. See the list of available serial ports for each board on the Serial main page. Speed: in bits per second (baud). Allowed data types: long. Config: sets data, parity, and stop bits. Valid values are: SERIAL5N1 SERIAL6N1 SERIAL7N1 SERIAL8N1 (the default) SERIAL5N2 SERIAL6N2 SERIAL7N2 SERIAL8N2 SERIAL5E1: even. Serial may sound like a tasty breakfast food, but its actually quite different. The word serial means 'one after the other.' For example, a serial killer doesn't stop with one murder, but stabs many people one after the other. Serial data transfer is when we transfer data one bit at a time, one right after the other. Information is passed back & forth between the computer and Arduino. Buy Serial Wi-Fi Wireless -01 Adapter Module 3.3V / 5V Compatible for Arduino from Walmart Canada. Shop for more Wireless USB Adapters available online at Walmart.ca. As of Arduino IDE 1.0, serial transmission is asynchronous. If there is enough empty space in the transmit buffer, Serial.write will return before any characters are transmitted over serial. If the transmit buffer is full then Serial.write will block until there is enough space in the buffer. How to interface a servo motor with an arduino mega2560 using ros? Asked 2016-05-24 05:48:46 -0500.

Aug 22nd, 2011
Serial
Arduino serial read
Arduino serial read
Arduino
Arduino
Never

Arduino To Arduino Serial Communication

Not a member of Pastebin yet?Sign Up, it unlocks many cool features!
  1. * by zer044 arduino account holder
  2. * adaptions of Ken Sherriff IrLibary Example code.
  3. * http://www.arcfn.com/2009/08/multi-protocol-infrared-remote-library.html
  4. //ir reciver bit
  5. // define codes
  6. #define Button_1 0xFF30CF // 1 on remote
  7. #define Button_3 0xFF7A85 // 3 on remote
  8. IRrecv irrecv(RECV_PIN);
  9. int levelPins[]={
  10. int colPins[]={
  11. int x=0;// A COUNTER
  12. int pressed1=0;
  13. //ir receiver bit
  14. irrecv.enableIRIn();// Start the receiver
  15. //led cube bit
  16. for(int i=0; i<3; i++){
  17. }
  18. pinMode(colPins[j], OUTPUT);
  19. }
  20. void loop (){
  21. if(irrecv.decode(&results)){
  22. Serial.write('Button 1 pressedn');
  23. break;
  24. Serial.write('Button 2 pressedn');
  25. break;
  26. case Button_3:
  27. spinthroughlayers ();
  28. case OFF:
  29. allOff();
  30. Serial.println(results.value, HEX);
  31. irrecv.resume();// Receive the next value
  32. }
  33. }
  34. // all functions start here..
  35. * list of current functions
  36. * scrollupanddown ();
  37. **/
  38. // function turns all leds off
  39. void allOff (){
  40. digitalWrite(colPins[j], LOW);
  41. for(int i=0; i<3; i++){
  42. }
  43. //function to turn an LED on.
  44. digitalWrite(levelPins[x], LOW);
  45. delay(t);
  46. digitalWrite(levelPins[x], HIGH);
  47. for(int i=0; i<3; i++){
  48. ledOn(i,j,30);
  49. }
  50. }
  51. void spinthroughlayers (){
  52. while(x<30){
  53. ledOn(1,3,4);
  54. ledOn(1,4,4);
  55. ledOn(2,4,4);
  56. ledOn(1,5,4);
  57. x++;
  58. delay(50);
  59. //second layer
  60. ledOn(0,6,4);
  61. ledOn(2,6,4);
  62. ledOn(0,4,4);
  63. ledOn(0,2,4);
  64. ledOn(2,2,4);
  65. }
  66. x=0;
  67. while(x<30){
  68. ledOn(1,7,4);
  69. ledOn(1,4,4);
  70. ledOn(2,4,4);
  71. ledOn(1,1,4);
  72. x++;
  73. delay(50);
  74. // forth layer
  75. ledOn(0,8,4);
  76. ledOn(2,8,4);
  77. ledOn(0,4,4);
  78. ledOn(0,0,4);
  79. ledOn(2,0,4);
  80. }
  81. x=0;
  82. for(int d=0; d<3; d++){
  83. ledOn(d,0,4);
  84. ledOn(d,2,4);
  85. ledOn(d,4,4);
  86. ledOn(d,6,4);
  87. ledOn(d,8,4);
  88. }
  89. x=0;
  90. for(int d=2; d>-1; d--){
  91. ledOn(d,0,4);
  92. ledOn(d,2,4);
  93. ledOn(d,4,4);
  94. ledOn(d,6,4);
  95. ledOn(d,8,4);
  96. }
  97. x=0;
  98. }
RAW Paste Data

Serial Output Arduino

/** * by zer044 arduino account holder * 22/08/2011 * adaptions of Ken Sherriff IrLibary Example code. * http://www.arcfn.com/2009/08/multi-protocol-infrared-remote-library.html **/ //ir reciver bit #include <IRremote.h> // define codes #define OFF 0xFFA25D // ON/OFF button on remote #define Button_1 0xFF30CF // 1 on remote #define Button_2 0xFF18E7 // 2 on remote #define Button_3 0xFF7A85 // 3 on remote int RECV_PIN = 11; IRrecv irrecv(RECV_PIN); decode_results results; //led cube bit int levelPins[] = { 22,23,24}; int colPins[] = { 30,31,32,33,34,35,36,37,38}; int x=0; // A COUNTER int c=0; // JUST ANOTHER COUNTER int pressed1=0; // check if another is pressed void setup () { //ir receiver bit Serial.begin(9600); irrecv.enableIRIn(); // Start the receiver //led cube bit //set all output for (int i=0; i<3; i++) { pinMode(levelPins[i], OUTPUT); } for (int j=0; j<9; j++) { pinMode(colPins[j], OUTPUT); } } void loop () { //ir receiver bit if (irrecv.decode(&results)) { switch (results.value) { case Button_1: Serial.write('Button 1 pressedn'); scrollthroughled (); break; case Button_2: Serial.write('Button 2 pressedn'); scrollupanddown (); break; case Button_3: Serial.write('Button 3 pressedn'); spinthroughlayers (); break; case OFF: Serial.write('ON/OFF pressedn'); allOff(); break; default : Serial.println(results.value, HEX); } irrecv.resume(); // Receive the next value } } // all functions start here.. /** * list of current functions * scrollthroughled (); * scrollupanddown (); * spinthroughlayers (); **/ // function turns all leds off void allOff () { for (int j=0; j<9; j++) { digitalWrite(colPins[j], LOW); } for (int i=0; i<3; i++) { digitalWrite(levelPins[i], HIGH); } } //function to turn an LED on. int ledOn (int x, int y, int t) { digitalWrite(levelPins[x], LOW); digitalWrite(colPins[y], HIGH); delay(t); digitalWrite(colPins[y], LOW); digitalWrite(levelPins[x], HIGH); } void scrollthroughled () { for(int i=0; i<3; i++) { for(int j=0; j<9; j++) { ledOn(i,j,30); delay(150); } } } void spinthroughlayers () { //middle layer while(x<30) { ledOn(0,3,4); ledOn(1,3,4); ledOn(2,3,4); ledOn(1,4,4); ledOn(0,4,4); ledOn(2,4,4); ledOn(0,5,4); ledOn(1,5,4); ledOn(2,5,4); x++; } delay(50); x=0; //second layer while(x<30) { ledOn(0,6,4); ledOn(1,6,4); ledOn(2,6,4); ledOn(1,4,4); ledOn(0,4,4); ledOn(2,4,4); ledOn(0,2,4); ledOn(1,2,4); ledOn(2,2,4); x++; } delay(50); x=0; // third layer while(x<30) { ledOn(0,7,4); ledOn(1,7,4); ledOn(2,7,4); ledOn(1,4,4); ledOn(0,4,4); ledOn(2,4,4); ledOn(0,1,4); ledOn(1,1,4); ledOn(2,1,4); x++; } delay(50); x=0; // forth layer while(x<30) { ledOn(0,8,4); ledOn(1,8,4); ledOn(2,8,4); ledOn(1,4,4); ledOn(0,4,4); ledOn(2,4,4); ledOn(0,0,4); ledOn(1,0,4); ledOn(2,0,4); x++; } delay(50); x=0; } void scrollupanddown () { for (int d=0; d<3; d++) { while(x < 30) { ledOn(d,0,4); ledOn(d,1,4); ledOn(d,2,4); ledOn(d,3,4); ledOn(d,4,4); ledOn(d,5,4); ledOn(d,6,4); ledOn(d,7,4); ledOn(d,8,4); x++; } delay(30); x=0; } for (int d=2; d>-1; d--) { while(x < 30) { ledOn(d,0,4); ledOn(d,1,4); ledOn(d,2,4); ledOn(d,3,4); ledOn(d,4,4); ledOn(d,5,4); ledOn(d,6,4); ledOn(d,7,4); ledOn(d,8,4); x++; } x=0; delay(30); } }



broken image