Programming Flashcards
map()
map(value, fromLow, fromHigh, toLow, toHigh)
Re-maps a number from one range to another. A value of “fromLow” gets mapped to “toLow” and a value of “fromHigh” gets mapped to “toHigh”. Ex) an analog value to 8 bits (go from range 0 to 255 to range 0 to 1023)
analogReadResolution()
analogWriteResolution()
analogReadResolution(bits)
In some arduino boards (like MKR) the default read resolution is 10 bits but has capabilities of up to 12 bits. (write default is 8 bits but can go up to 12) You can set the resolution you want by choosing the argument (bits). (you might be able to do it in uno, havent tried)
noTone()
noTone(pin)
Stops the generation of a square wave triggered by tone(). Has no effect if the tone hasnt been generated.
(if you want to have different tones on multiple pins, you might have to call noTone() on one pin before calling tone() on the next)
pulseIn()
pulseIn(pin, value, timeout)
timeout is optional, default is one second.
Reads a pulse (either HIGH or LOW) on a pin. If value is HIGH, the method waits for the pin to go from low to high, starts timing, then wait for the pin to go to low and stops timing. Returns the length of the pulse in microseconds or returns 0 if no complete pulse was received within the timeout
shiftIn()
shiftOut()
idk
tone()
tone(pin, frequency, duration)
duration is optional, otherwise until noTone() is called.
Generates a square wave of the specifies freq. (and 50% duty cycle)
different delays (pauses in the program)
delay(ms)
delayMicroseconds(us)
micros()
millis()
time passed since the arduino board began running the current program.
micros() resolution of a few microseconds. Goes back to 0 after 70 minutes
millis() resolution of milliseconds. Goes back to 0 after 50 days
constrain()
constrain(x, a, b)
constrains a number to be within a range.
x is the number to constrain. If x is between a and b, then x is returned. If its below a, a is returned. If its above b, b is returned.
Dont have operations inside (), it can yield incorrect results. Only values.
max()
min()
max(x, y)
min(x, y)
returns the larger or the lower of the two numbers
sq()
the number to the power of 2
isAlpha()
isAlpha(thisChar)
Checks if the char is a letter.
isAlphaNumeric()
isAlphaNumeric(thisChar)
Checks if the char is a letter or a number
isAscii()
isAscii(thisChar)
Checks if the char is an ASCII character
isControl()
isControl(thisChar)
Checks if the char is a control letter