Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2020
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. //www.elegoo.com
  2. //2016.12.08
  3.  
  4. #include "Wire.h" // This library allows you to communicate with I2C devices.
  5. const int MPU_ADDR = 0x68; // I2C address of the MPU-6050. If AD0 pin is set to HIGH, the I2C address will be 0x69.
  6. int16_t accelerometer_x, accelerometer_y, accelerometer_z; // variables for accelerometer raw data
  7. int16_t gyro_x, gyro_y, gyro_z; // variables for gyro raw data
  8. int16_t temperature; // variables for temperature data
  9. char tmp_str[7]; // temporary variable used in convert function
  10. char* convert_int16_to_str(int16_t i) { // converts int16 to string. Moreover, resulting strings will have the same length in the debug monitor.
  11. sprintf(tmp_str, "%6d", i);
  12. return tmp_str;
  13. }
  14. //int redPin = 5;
  15. //int greenPin= 6;
  16. //int buttonOnpin = 9;
  17. //int buttonOffpin = 8;
  18.  
  19. int redPin = 11;
  20. int greenPin= 8;
  21. int buttonOnpin = 2;
  22. int buttonOffpin = 3;
  23.  
  24.  
  25. boolean isOn = false;
  26. unsigned long previousMillis = 0;
  27. const long interval = 1000;
  28.  
  29. byte leds = 0;
  30.  
  31. void setup()
  32. {
  33. pinMode(redPin, OUTPUT);
  34. pinMode(greenPin, OUTPUT);
  35. pinMode(buttonOnpin, INPUT_PULLUP);
  36. pinMode(buttonOffpin, INPUT_PULLUP);
  37. Serial.begin(9600);
  38. Wire.begin();
  39. Wire.beginTransmission(MPU_ADDR); // Begins a transmission to the I2C slave (GY-521 board)
  40. Wire.write(0x6B); // PWR_MGMT_1 register
  41. Wire.write(0); // set to zero (wakes up the MPU-6050)
  42. Wire.endTransmission(true);
  43. }
  44.  
  45. void loop()
  46. {
  47. unsigned long currentMillis = millis();
  48.  
  49. if (currentMillis - previousMillis >= interval)
  50. {
  51. previousMillis = currentMillis;
  52. }
  53. if (digitalRead(buttonOnpin) == LOW and digitalRead(buttonOffpin) == LOW)
  54. {
  55. digitalWrite(greenPin, HIGH);
  56. digitalWrite(greenPin, LOW);
  57. }
  58.  
  59. if (digitalRead(buttonOnpin) == LOW or digitalRead(buttonOffpin) == LOW)
  60. {
  61. digitalWrite(redPin, HIGH);
  62. digitalWrite(redPin, LOW);
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement