Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Analog input, analog output, serial output
- This sketch is intended to be a "Hello World" piece of a tutorial which translates serial communication between
- Unreal 4 and Arduino
- Reads an analog input pin, maps the result to a range from 0 to 255
- and uses the result to set the pulsewidth modulation (PWM) of an output pin.
- Also prints the results to the serial monitor.
- The circuit:
- * potentiometer connected to analog pins 0, 1 and 2.
- Center pin of the potentiometer goes to the analog pin.
- side pins of the potentiometer go to +5V and ground
- * push button connected to digital pin.
- created 29 Dec. 2008, modified 9 Apr 2012, by Tom Igoe
- modified 23 February 2016, by Shaun Foster
- */
- // These constants won't change. They're used to give names
- // to the pins used:
- const int analogInPin1 = A0; // Analog input pin that the potentiometer is attached to
- const int analogInPin2 = A1;
- const int analogInPin3 = A2;
- // digital pin 2 has a pushbutton attached to it.
- int pushButton = 2;
- void setup() {
- Serial.begin(9600);
- // make the pushbutton's pin an input:
- pinMode(pushButton, INPUT);
- }
- void loop() {
- // print the results to the serial monitor:
- Serial.print(analogRead(analogInPin1));
- Serial.print(",");
- Serial.print(analogRead(analogInPin2));
- Serial.print(",");
- Serial.print(analogRead(analogInPin3));
- Serial.print(",");
- // read the input pin:
- int buttonState = digitalRead(pushButton);
- // print out the state of the button:
- Serial.print(buttonState);
- Serial.print("\n");
- delay(100);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement