Advertisement
pleasedontcode

pro1 rev_01

Nov 15th, 2023
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: pro1
  13.     - Source Code compiled for: Arduino Mega
  14.     - Source Code created on: 2023-11-15 07:09:24
  15.     - Source Code generated by: Gopinath
  16.  
  17. ********* Pleasedontcode.com **********/
  18. /****** DEFINITION OF LIBRARIES *****/
  19. #include <SPI.h>
  20. #include <SdFat.h>
  21.  
  22. /****** SYSTEM REQUIREMENT 1 *****/
  23. /* turn on and turn off light of led should press the */
  24. /* button */
  25.  
  26. /****** FUNCTION PROTOTYPES *****/
  27. void setup(void);
  28. void loop(void);
  29.  
  30. /***** DEFINITION OF SPI PINS *****/
  31. const uint8_t butt1_SDCardModule_SPI_PIN_MOSI_D51 = 51;
  32. const uint8_t butt1_SDCardModule_SPI_PIN_MISO_D50 = 50;
  33. const uint8_t butt1_SDCardModule_SPI_PIN_SCLK_D52 = 52;
  34. const uint8_t butt1_SDCardModule_SPI_PIN_CS_D53 = 53;
  35.  
  36. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  37. SdFat sd; // Instantiate SdFat object
  38.  
  39. // Define button and LED pins
  40. const uint8_t buttonPin = 2;
  41. const uint8_t ledPin = 3;
  42.  
  43. void setup(void)
  44. {
  45.   pinMode(butt1_SDCardModule_SPI_PIN_CS_D53, OUTPUT);
  46.   // start the SPI library:
  47.   SPI.begin();
  48.  
  49.   // Initialize SD card
  50.   if (!sd.begin(butt1_SDCardModule_SPI_PIN_CS_D53, SD_SCK_MHZ(4))) {
  51.     Serial.println("SD initialization failed.");
  52.     while (1);
  53.   }
  54.  
  55.   pinMode(buttonPin, INPUT);
  56.   pinMode(ledPin, OUTPUT);
  57. }
  58.  
  59. void loop(void)
  60. {
  61.   // Check if the button is pressed
  62.   if (digitalRead(buttonPin) == HIGH) {
  63.     // Turn on the LED
  64.     digitalWrite(ledPin, HIGH);
  65.   } else {
  66.     // Turn off the LED
  67.     digitalWrite(ledPin, LOW);
  68.   }
  69. }
  70.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement