Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //prime number generator
- #include <Wire.h>
- #include <Adafruit_MCP23017.h>
- #include <Adafruit_RGBLCDShield.h>
- Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();
- unsigned long check = 2;
- unsigned long found = 1;
- unsigned long timeNow = 0;
- void setup() {
- Serial.begin(57600);
- lcd.begin(16, 2);
- //while(!Serial);
- }
- void loop() {
- if (isPrime(check) == 1) {
- Serial.print(found);
- Serial.print(F(" "));
- Serial.println(check);
- found ++;
- }
- //if (check > 1000) {
- // while(1);
- //}
- if (millis() - timeNow > 1000) {
- lcd.setCursor (0, 0);
- lcd.print(F("found "));
- lcd.print(found);
- lcd.setCursor(0, 1);
- lcd.print(F("in "));
- lcd.print(millis() / 1000);
- lcd.print(F("s. "));
- lcd.print(check);
- timeNow = millis();
- }
- check ++;
- }
- int isPrime(unsigned long test) {
- for (unsigned long div = 2; div <= sqrt(test); div ++) {
- if ((test % div == 0)) {
- return 0;
- }
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement