Base class that Arduino-like sketches can extend.
More...
|
| | Sketch (TreehopperUsb board, bool throwExceptions=true) |
| | Initialize and run a sketch More...
|
| |
| void | Run () |
| | Run the sketch synchronously More...
|
| |
| abstract void | setup () |
| | Implement this function in your sketch to provide one-time setup functionality More...
|
| |
| abstract void | loop () |
| | Implement this function in your sketch that gets called repeatedly until the program exits. More...
|
| |
| void | pinMode (int pin, int mode) |
| | Configures the specified pin to behave either as an input or an output. More...
|
| |
| void | digitalWrite (int pin, bool value) |
| | Write a HIGH or a LOW value to a digital pin. More...
|
| |
| bool | digitalRead (int pin) |
| | Reads the value from a specified digital pin, either HIGH or LOW. More...
|
| |
| int | analogRead (int pin) |
| | Reads the value from the specified analog pin. More...
|
| |
| void | analogWrite (int pin, int value) |
| | Writes a PWM value to a pin. More...
|
| |
| void | analogWriteResolution (int bits) |
| | Set the number of bits used for PWM resolution More...
|
| |
| void | analogReadResolution (int bits) |
| | Sets the number of bits used for ADC resolution More...
|
| |
| long | millis () |
| | Returns the number of milliseconds since the current sketch started running More...
|
| |
| long | micros () |
| | Returns the number of microseconds since the current sketch started running More...
|
| |
| void | delay (int ms) |
| | Pauses the program for the amount of time (in miliseconds) specified as parameter. More...
|
| |
| double | map (double value, double fromLow, double fromHigh, double toLow, double toHigh) |
| | Re-maps a number from one range to another. More...
|
| |
| double | constrain (double x, double a, double b) |
| | Constrains a number to be within a range More...
|
| |
Base class that Arduino-like sketches can extend.
◆ Sketch()
Initialize and run a sketch
- Parameters
-
| board | The Treehopper board to use |
| throwExceptions | Whether unimplemented or miscalled functions should throw exceptions or fail silently |
◆ Run()
Run the sketch synchronously
◆ setup()
Implement this function in your sketch to provide one-time setup functionality
◆ loop()
Implement this function in your sketch that gets called repeatedly until the program exits.
◆ pinMode()
| void pinMode |
( |
int |
pin, |
|
|
int |
mode |
|
) |
| |
Configures the specified pin to behave either as an input or an output.
- Parameters
-
| pin | the number of the pin whose mode you wish to set |
| mode | INPUT, OUTPUT, or INPUT_PULLUP. Note that Treehopper inputs are always weakly pulled-up, so there is no difference between INPUT and INPUT_PULLUP |
◆ digitalWrite()
| void digitalWrite |
( |
int |
pin, |
|
|
bool |
value |
|
) |
| |
Write a HIGH or a LOW value to a digital pin.
To set the LED, use "LedPin"
- Parameters
-
| pin | the pin number (or ledPin) |
| value | HIGH or LOW |
◆ digitalRead()
| bool digitalRead |
( |
int |
pin | ) |
|
Reads the value from a specified digital pin, either HIGH or LOW.
- Parameters
-
| pin | the number of the digital pin you want to read (int) |
- Returns
- bool true or false (can compare with HIGH or LOW)
◆ analogRead()
| int analogRead |
( |
int |
pin | ) |
|
Reads the value from the specified analog pin.
- Parameters
-
| pin | the number of the analog input pin to read from |
- Returns
- int (0 to 2^analogReadResolution – 1024 by default)
◆ analogWrite()
| void analogWrite |
( |
int |
pin, |
|
|
int |
value |
|
) |
| |
Writes a PWM value to a pin.
Uses zero-jitter hardware PWM on pins 7, 9, and 9. Uses software PWM on all other pins.
- Parameters
-
| pin | the pin to write to |
| value | the duty cycle between 0 (always off) and 2^analogWriteResolution (defaults to 255) (always on) |
◆ analogWriteResolution()
| void analogWriteResolution |
( |
int |
bits | ) |
|
Set the number of bits used for PWM resolution
- Parameters
-
| bits | The number of bits to use |
◆ analogReadResolution()
| void analogReadResolution |
( |
int |
bits | ) |
|
Sets the number of bits used for ADC resolution
- Parameters
-
| bits | The number of bits to use |
◆ millis()
Returns the number of milliseconds since the current sketch started running
- Returns
- the number of milliseconds since the program started
◆ micros()
Returns the number of microseconds since the current sketch started running
- Returns
- the number of microseconds since the program started
◆ delay()
Pauses the program for the amount of time (in miliseconds) specified as parameter.
- Parameters
-
| ms | the number of milliseconds to pause |
◆ map()
| double map |
( |
double |
value, |
|
|
double |
fromLow, |
|
|
double |
fromHigh, |
|
|
double |
toLow, |
|
|
double |
toHigh |
|
) |
| |
Re-maps a number from one range to another.
- Parameters
-
| value | the number to map |
| fromLow | the lower bound of the value's current range |
| fromHigh | the upper bound of the value's current range |
| toLow | the lower bound of the value's target range |
| toHigh | the upper bound of the value's target range |
- Returns
- the mapped value
◆ constrain()
| double constrain |
( |
double |
x, |
|
|
double |
a, |
|
|
double |
b |
|
) |
| |
Constrains a number to be within a range
- Parameters
-
| x | the number to constrain |
| a | the lower end of the range |
| b | the upper end of the range |
- Returns
- the constrained number
◆ INPUT
◆ OUTPUT
◆ INPUT_PULLUP
| const int INPUT_PULLUP = 3 |
Input, with pullup, for pins.
◆ HIGH
Logic high: 3.3V on most boards.
◆ LOW
Logic low: 0V on most boards.
◆ ledPin
| const int ledPin = int.MaxValue |
ledPin is pre-defined for use with digitalWrite().
To avoid bus contention, Treehopper's LED pin is not attached to a user-accessible GPIO pin, so int.MaxValue is used as a hack. The digitalWrite(int, bool) function intercepts this value and directs write operations to the LED.
◆ MSBFIRST
| const bool MSBFIRST = true |
◆ LSBFIRST
| const bool LSBFIRST = false |
◆ Serial
The Serial port to use with this sketch.
◆ Board
The board to use with this sketch.
The documentation for this class was generated from the following file:
- F:/Git/treehopper-sdk/NET/API/Treehopper.Libraries/ArduinoShim/Sketch.cs