Arduino Code For "The Sensor Seat"


/ Published in: Processing
Save to your folder(s)

Final project for module Performance Technology 2.
Lecturer: Nick Ward


Copy this code and paste it in your HTML
  1. void setup()
  2. {
  3. Serial.begin(57600); //sets speed at which data is read from Arduino.
  4.  
  5. analogReference(EXTERNAL); //sets Arduino board voltage reference to external input
  6. pinMode(A0, OUTPUT); //sets A0 pin to output mode
  7. pinMode(A1, OUTPUT); //sets A1 pin to output mode
  8. digitalWrite(A0, HIGH); //A0 pin outputs reference voltage
  9. digitalWrite(A1, LOW); //A1 acts as a ground (GRD) output.
  10.  
  11. pinMode(2,INPUT_PULLUP); //sets digital pin 2 to a known state when no input is present
  12. pinMode(3,INPUT_PULLUP); //sets digital pin 3 to a known state when no input is present
  13.  
  14. }
  15.  
  16.  
  17. void loop() //initiate loop
  18. {
  19.  
  20. int Result = analogRead(A3); //sets variable "Result" to be whatever is coming into A3 pin. In this case, it is the Y-axis of accelerometer.
  21. Serial.write (Result >> 7);
  22. Serial.write (Result%128);
  23.  
  24. int Switch1 = digitalRead(2); //sets variable "Switch1" to whatever data is coming from digital pin 2
  25. Serial.write(Switch1); //sends "Switch1" data to serial port.
  26.  
  27. int Switch2 = digitalRead(3); //sets variable "Switch2" to whatever data is coming from digital pin 3
  28. Serial.write(Switch2); //sends "Switch2" data to serial port.
  29.  
  30.  
  31. Serial.write(255); //sends the value 255 to signify the end of one round of the loop to the Max/MSP patch.
  32.  
  33.  
  34. delay(10); //delays the loop by 10 milliseconds
  35. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.