FUNCTIONS Flashcards

1
Q

pinMode(pin, mode)

A

Purpose: Sets the mode of a specified pin (INPUT, OUTPUT).
Example:
pinMode(13, OUTPUT);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

digitalWrite(pin, value)

A

Purpose: Write a HIGH or LOW value to a pin.
Example:
digitalWrite(13, HIGH);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

digitalRead(pin)

A

Purpose: Reads the value from a specified digital pin.
Example:
int buttonState = digitalRead(7);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

analogWrite(pin, value)

A

Purpose: Write an analog value (PWM wave) to a pin.
Example:
analogWrite(9, 128);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

analogRead(pin)

A

Purpose: Reads the analog value from a pin.
Example:
int sensorValue = analogRead(A0);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

delay(ms)

A

Purpose: Pauses the program for a specified time.
Example:
delay(1000);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

millis()

A

Purpose: Returns the number of milliseconds since the board started.
Example:
unsigned long time = millis();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Serial.begin(baudrate)

A

Purpose: Initializes serial communication at a certain baud rate.
Example:
Serial.begin(9600);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Serial.print(data)

A

Purpose: Prints data to the serial monitor.
Example:
Serial.print(“Hello, world!”);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Serial.println(data)

A

Purpose: Prints data followed by a new line.
Example:
Serial.println(“Line 1”);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

attachInterrupt(digitalPinToInterrupt(pin), ISR, mode)

A

Purpose: Attaches an interrupt to a pin.
Example:
attachInterrupt(digitalPinToInterrupt(2), blink, RISING);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

detachInterrupt(pin)

A

Purpose: Disables an interrupt attached to a pin.
Example:
detachInterrupt(digitalPinToInterrupt(2));

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

map(value, fromLow, fromHigh, toLow, toHigh)

A

Purpose: Re-maps a number from one range to another.
Example:
int output = map(analogRead(A0), 0, 1023, 0, 255);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

constrain(value, min, max)

A

Purpose: Constrains a number to be within a range.
Example:
int val = constrain(analogRead(A0), 100, 900);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

randomSeed(seed)

A

Purpose: Initializes the pseudo-random number generator.
Example:
randomSeed(analogRead(0));

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

random(min, max)

A

Purpose: Generates a random number between a given range.
Example:
int randNum = random(1, 10);

17
Q

noTone(pin)

A

Purpose: Stops the tone on a pin.
Example:
noTone(8);

18
Q

tone(pin, frequency)

A

Purpose: Generates a square wave of a certain frequency on a pin.
Example:
tone(8, 1000);

19
Q

shiftOut(dataPin, clockPin, bitOrder, value)

A

Purpose: Shifts out a byte of data one bit at a time.
Example:
shiftOut(11, 12, MSBFIRST, 0xFF);

20
Q

shiftIn(dataPin, clockPin, bitOrder)

A

Purpose: Shifts in a byte of data one bit at a time.
Example:
byte myData = shiftIn(11, 12, MSBFIRST);

21
Q

pulseIn(pin, value)

A

Purpose: Reads a pulse (HIGH or LOW) on a pin.
Example:
unsigned long duration = pulseIn(7, HIGH);

22
Q

min(x, y)

A

Purpose: Returns the smaller of two numbers.
Example:
int smaller = min(10, 20);

23
Q

max(x, y)

A

Purpose: Returns the larger of two numbers.
Example:
int larger = max(10, 20);

24
Q

abs(x)

A

Purpose: Returns the absolute value of a number.
Example:
int absolute = abs(-5);

25
Q

sqrt(x)

A

Purpose: Calculates the square root of a number.
Example:
float root = sqrt(16);

26
Q

pow(base, exponent)

A

Purpose: Raises a number to a given power.
Example:
float result = pow(2, 3); // 2 raised to the power of 3

27
Q

sin(angle)

A

Purpose: Calculates the sine of an angle (in radians).
Example:
float sineValue = sin(PI / 2);

28
Q

cos(angle)

A

Purpose: Calculates the cosine of an angle (in radians).
Example:
float cosineValue = cos(PI);

29
Q

tan(angle)

A

Purpose: Calculates the tangent of an angle (in radians).
Example:
float tanValue = tan(PI / 4);

30
Q

lowByte(x)

A

Purpose: Extracts the low byte of a two-byte number.
Example:
byte lower = lowByte(0xABCD);

31
Q

highByte(x)

A

Purpose: Extracts the high byte of a two-byte number.
Example:
byte higher = highByte(0xABCD);

32
Q

bitRead(value, bit)

A

Purpose: Reads a specific bit of a number.
Example:
int bitValue = bitRead(0b1010, 2); // Read bit 2

33
Q

bitWrite(value, bit, bitValue)

A

Purpose: Writes a specific bit of a number.
Example:
bitWrite(x, 1, 1); // Set bit 1 of x to 1

34
Q

bitSet(value, bit)

A

Purpose: Sets a specific bit of a number to 1.
Example:
bitSet(x, 1); // Set bit 1 to 1

35
Q

bitClear(value, bit)

A

Purpose: Clears a specific bit of a number (sets it to 0).
Example:
bitClear(x, 1); // Clear bit 1

36
Q

bit(bit)

A

Purpose: Returns the value of a specific bit.
Example:
byte myBit = bit(3); // Returns 0b1000

37
Q
A