Introducing 

Prezi AI.

Your new presentation assistant.

Refine, enhance, and tailor your content, source relevant images, and edit visuals quicker than ever before.

Loading…
Transcript

int analogPin = 3;

void setup()

{

Serial.begin(9600);

}

void loop()

{

int val = analogRead(analogPin);

Serial.println(val);

}

int ledPin = 9;

int analogPin = 3;

void setup()

{

pinMode(ledPin, OUTPUT);

}

void loop()

{

int val = analogRead(analogPin);

analogWrite(ledPin, val / 4); // analogRead values go from 0 to 1023, analogWrite values from 0 to 255

}

Analog input & output

Tools & Tech W3

Signals

Data Structures

Declaring Arrays

Reading an analog signal

int analogRead(int pin)

10-bit ADC so returns values between 0 and 1023

  • Arrays
  • Structures

Each unit equals 5V / 1024 = 0.0049V per unit

e.g. a value of 200 units would equal 0.98 or ~1V

int myInts[6];

int myPins[] = {2, 4, 8, 3, 6};

int mySensVals[6] = {2, 4, -8, 3, 2};

char message[6] = "hello";

One read takes ~100 microseconds, or 0.0001 seconds

Retrieve the value of an array element

Assign a value to an array element

Defining a structure

Declaring a variable of a structure type

int x = myPins[1];

myPins[1] = 5;

myPins = [ 0, 5, 2, 3, 4 ]

Write an analog signal (PWM)

Pulse Width Modulation (PWM)

Result = [ 0, 5, 2, 3, 4 ]

So x now contains 5

struct color {

byte red;

byte green;

byte blue;

};

struct color myColor = { 255, 255, 255 };

void analogWrite(int pin, byte value)

Strings

Most pins ~490 Hz

char Str1[15];

char Str2[8] = {'a', 'r', 'd', 'u', 'i', 'n', 'o'};

char Str3[8] = {'a', 'r', 'd', 'u', 'i', 'n', 'o', '\0'};

char Str4[ ] = "arduino";

char Str5[8] = "arduino";

char Str6[15] = "arduino";

Pins 5 and 6 are ~980 Hz

Assign a value to a structure member

Retrieve the value of a structure member

Examples

myColor.red = 128;

myColor.green = 0;

myColor.blue = 0;

byte red = myColor.red;

byte green = myColor.green;

byte blue = myColor.blue;

http://arduino.cc/en/Tutorial/Tone

http://arduino.cc/en/Tutorial/Tone2

http://arduino.cc/en/Tutorial/Knock

http://www.cutedigi.com/arduino/sensors-kit-for-arduino.html

CapSense

Drawdio

Learn more about creating dynamic, engaging presentations with Prezi