Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This is a demonstration of a custom library for Arduino use.
- // filename: Morse_halford88.cpp
- // August 20, 2018
- #include "Arduino.h"
- #include "Morse_halford88.h"
- Morse_halford88::Morse_halford88(int pin)
- {
- //pinMode(pin, OUTPUT); //<-------------------This line cannot go here !!!!!!!!!!!!!!
- /*
- The reason is as follows:
- In the Arduino sketch (and in C/C++) when you declare the instance of the class,
- the ONLY thing you are allowed to do is assign values to variables.
- You are not allowed to make ANY function calls,
- and setting the pinMode is a function call.
- I think I saw this mentioned on an Adafruit page about writing libraries, but I can't find it now.
- 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.
- */
- _pin = pin; // <-----this line is okay, since it is only assigning a value to a variable.
- }
- void Morse_halford88::setUpValues() {
- /*
- This method is what I made to set up the pinMode.
- 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.
- Since this function is called within the setup() function of the arduino sketch,
- you are allowed to call other functions in here.
- */
- pinMode(_pin, OUTPUT);
- }
- void Morse_halford88::dot()
- {
- digitalWrite(_pin, HIGH);
- delay(250);
- digitalWrite(_pin, LOW);
- delay(250);
- }
- void Morse_halford88::dash()
- {
- digitalWrite(_pin, HIGH);
- delay(1000);
- digitalWrite(_pin, LOW);
- delay(250);
- }
Advertisement
Add Comment
Please, Sign In to add comment