Arduino MetroPhones


  1. // MetroPhones
  2. // pkvi
  3. #include "SPI.h"
  4. // Chip Select Pin
  5. int csp = 10;
  6. // Sensor Values
  7. long dur, dis;
  8. // Echo Pin
  9. int echo = 4;
  10. // Trigger Pin
  11. int trig = 5;
  12. // Position
  13. int pos = 0;
  14. // Centimeters
  15. // Minimum Distance
  16. int mindis = 0;
  17. // Maximum Distance
  18. int maxdis = 90; // 2.6FT
  19. void setup() {
  20. // Pot Com
  21. SPI.begin();
  22. pinMode(csp, OUTPUT);
  23. // Set Chip Select LOW
  24. digitalWrite(csp, LOW);
  25. // Testing
  26. Serial.begin (9600);
  27. // Sensor Pins
  28. pinMode(trig, OUTPUT);
  29. pinMode(echo, INPUT);
  30. }
  31. void loop() {
  32. // Poll Sensor
  33. digitalWrite(trig, HIGH);
  34. delay(10);
  35. digitalWrite(trig, LOW);
  36. dur = pulseIn(echo, HIGH);
  37. // Convert to Centimeters
  38. dis = dur / 58.2;
  39. if (dis < maxdis) {
  40. // Convert Distance to Pot (256 Steps)
  41. pos = map(dis, mindis, maxdis, 0, 255);
  42. // Alert Chip
  43. SPI.transfer(0);
  44. // Adjust Volume
  45. SPI.transfer(pos);
  46. } else if (dis > maxdis) {
  47. pos = 255;
  48. SPI.transfer(0);
  49. SPI.transfer(pos);
  50. }
  51. // Testing
  52. Serial.print(dis);
  53. Serial.print(" ");
  54. Serial.println(pos);
  55. delay(100);
  56. }

Menu
Index
Engineering
Entertainment
Literature
Miscellaneous
Contact
Search
tiktok.com/@pkvi.xyz
scored.co/u/pkvi_apostate
Why Ayh?
Miter
Miter
@pkvi
"...may not meet professional standards."
3,138 miters
123 tenons
Subscribe
0.00407