pleasedontcode

Prime Finder rev_02

Dec 8th, 2025
35
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: Prime Finder
  13.     - Source Code NOT compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2025-12-08 15:27:05
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Generate a Graph of the water flow and the water */
  21.     /* pressure. */
  22. /****** END SYSTEM REQUIREMENTS *****/
  23.  
  24.  
  25. /* START CODE */
  26.  
  27. /****** DEFINITION OF LIBRARIES *****/
  28. #include <WiFiProvisioner.h>  //https://github.com/SanteriLindfors/WiFiProvisioner
  29. #include <FlowSensor.h>  //https://github.com/hafidhh/FlowSensor-Arduino
  30.  
  31. /****** FUNCTION PROTOTYPES *****/
  32. void setup(void);
  33. void loop(void);
  34.  
  35. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  36. const uint8_t esp32_YF-B1_OUT_PIN_D13      = 13;
  37. const uint8_t esp32_YF-S201_OUT_PIN_D4       = 4;
  38.  
  39. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  40.  
  41. unsigned long startTime;
  42. unsigned long duration = 30000; // 30 seconds
  43. unsigned long currentNumber = 2;
  44. unsigned long maxPrime = 2;
  45.  
  46. bool isPrime(unsigned long n) {
  47.   if (n < 2) return false;
  48.   if (n % 2 == 0 && n != 2) return false;
  49.   for (unsigned long i = 3; i * i <= n; i += 2) {
  50.     if (n % i == 0) return false;
  51.   }
  52.   return true;
  53. }
  54.  
  55. void setup() {
  56.   Serial.begin(115200);
  57.   startTime = millis();
  58.   pinMode(esp32_YF-B1_OUT_PIN_D13,  INPUT);
  59.   pinMode(esp32_YF-S201_OUT_PIN_D4,  INPUT);
  60. }
  61.  
  62. void loop() {
  63.   if (millis() - startTime < duration) {
  64.     if (isPrime(currentNumber)) {
  65.       maxPrime = currentNumber;
  66.     }
  67.     currentNumber++;
  68.   } else {
  69.     Serial.print("Highest prime found in 30 seconds: ");
  70.     Serial.println(maxPrime);
  71.     while (true) {} // Stop the program
  72.   }
  73. }
  74.  
  75. /* END CODE */
  76.  
Advertisement
Add Comment
Please, Sign In to add comment