skizziks_53

Morse_halford88_cpp

Aug 20th, 2018
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. // This is a demonstration of a custom library for Arduino use.
  2. // filename: Morse_halford88.cpp
  3. // August 20, 2018
  4.  
  5. #include "Arduino.h"
  6. #include "Morse_halford88.h"
  7.  
  8. Morse_halford88::Morse_halford88(int pin)
  9. {
  10. //pinMode(pin, OUTPUT); //<-------------------This line cannot go here !!!!!!!!!!!!!!
  11. /*
  12. The reason is as follows:
  13. In the Arduino sketch (and in C/C++) when you declare the instance of the class,
  14. the ONLY thing you are allowed to do is assign values to variables.
  15. You are not allowed to make ANY function calls,
  16. and setting the pinMode is a function call.
  17.  
  18. I think I saw this mentioned on an Adafruit page about writing libraries, but I can't find it now.
  19. This is the reason that so many library files have a class/instance start-up function that you must call in the setup() of the Arduino sketch.
  20. */
  21. _pin = pin; // <-----this line is okay, since it is only assigning a value to a variable.
  22.  
  23. }
  24.  
  25. void Morse_halford88::setUpValues() {
  26. /*
  27. This method is what I made to set up the pinMode.
  28.  
  29. After you declare an instance of the Morse_halford88 class, you must call this function in setup() of the Arduino sketch to set the output pinMode.
  30.  
  31. Since this function is called within the setup() function of the arduino sketch,
  32. you are allowed to call other functions in here.
  33. */
  34. pinMode(_pin, OUTPUT);
  35. }
  36.  
  37.  
  38. void Morse_halford88::dot()
  39. {
  40. digitalWrite(_pin, HIGH);
  41. delay(250);
  42. digitalWrite(_pin, LOW);
  43. delay(250);
  44. }
  45.  
  46. void Morse_halford88::dash()
  47. {
  48. digitalWrite(_pin, HIGH);
  49. delay(1000);
  50. digitalWrite(_pin, LOW);
  51. delay(250);
  52.  
  53.  
  54. }
Advertisement
Add Comment
Please, Sign In to add comment