Advertisement
raderraderrader

UE4 Arduino Color Mixer

Aug 6th, 2019
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. /*
  2. Analog input, analog output, serial output
  3.  
  4. This sketch is intended to be a "Hello World" piece of a tutorial which translates serial communication between
  5. Unreal 4 and Arduino
  6.  
  7. Reads an analog input pin, maps the result to a range from 0 to 255
  8. and uses the result to set the pulsewidth modulation (PWM) of an output pin.
  9. Also prints the results to the serial monitor.
  10.  
  11. The circuit:
  12. * potentiometer connected to analog pins 0, 1 and 2.
  13. Center pin of the potentiometer goes to the analog pin.
  14. side pins of the potentiometer go to +5V and ground
  15. * push button connected to digital pin.
  16.  
  17. created 29 Dec. 2008, modified 9 Apr 2012, by Tom Igoe
  18. modified 23 February 2016, by Shaun Foster
  19. */
  20.  
  21. // These constants won't change. They're used to give names
  22. // to the pins used:
  23. const int analogInPin1 = A0; // Analog input pin that the potentiometer is attached to
  24. const int analogInPin2 = A1;
  25. const int analogInPin3 = A2;
  26. // digital pin 2 has a pushbutton attached to it.
  27. int pushButton = 2;
  28.  
  29. void setup() {
  30. Serial.begin(9600);
  31. // make the pushbutton's pin an input:
  32. pinMode(pushButton, INPUT);
  33. }
  34.  
  35. void loop() {
  36. // print the results to the serial monitor:
  37. Serial.print(analogRead(analogInPin1));
  38. Serial.print(",");
  39. Serial.print(analogRead(analogInPin2));
  40. Serial.print(",");
  41. Serial.print(analogRead(analogInPin3));
  42. Serial.print(",");
  43.  
  44. // read the input pin:
  45. int buttonState = digitalRead(pushButton);
  46.  
  47. // print out the state of the button:
  48. Serial.print(buttonState);
  49.  
  50. Serial.print("\n");
  51. delay(100);
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement