Etch A Sketch Joystick

Project tutorial by millerman4487

  • 2,461 views
  • 1 comment
  • 18 respects

Arduino Color Recognition

by millerman4487

  • 2,385 views
  • 4 comments
  • 21 respects

Simple Record and Playback

by millerman4487

  • 6,894 views
  • 7 comments
  • 60 respects


Replicated projects 0

 millerman4487 hasn't replicated any projects yet.

Respected projects 0

 millerman4487 hasn't respected any projects yet.
  • DIY Shock Sensor with a Speaker 5 days ago

    Try changing the values of these variables:

    int shockMin = 996;
    int shockMax = 1010;
    

    You can also view the data in the serial monitor to help find the right values.

  • Arduino Color Recognition 5 days ago

    It sounds like you left out the functions below the void loop() function. I think that you just need to copy and paste these in:

    void decideColor() {//format color values
     //Limit possible values:
     redColor = constrain(redColor, 0, 255);
     greenColor = constrain(greenColor, 0, 255);
     blueColor = constrain(blueColor, 0, 255);
    
     //find brightest color:
     int maxVal = max(redColor, blueColor);
     maxVal = max(maxVal, greenColor);
     //map new values
     redColor = map(redColor, 0, maxVal, 0, 255);
     greenColor = map(greenColor, 0, maxVal, 0, 255);
     blueColor = map(blueColor, 0, maxVal, 0, 255);
     redColor = constrain(redColor, 0, 255);
     greenColor = constrain(greenColor, 0, 255);
     blueColor = constrain(blueColor, 0, 255);
    
     //light led
     analogWrite(redLED, redColor);
     analogWrite(greenLED, greenColor);
     analogWrite(blueLED, blueColor);
     //decide which color is present (you may need to change some values here):
     if (redColor > 250 && greenColor > 250 && blueColor > 250) {
       color = 1;//white
     }
     else if (redColor < 25 && greenColor < 25 && blueColor < 25) {
       color = 2;//black
     }
     else if (redColor > 200 &&  greenColor > 200 && blueColor < 100) {
       color = 4;//yellow
     }
     else if (redColor > 200 &&  greenColor > 25 /*&& blueColor < 100*/) {
       color = 3;//orange
     }
     else if (redColor > 200 &&  greenColor < 100 && blueColor > 200) {
       color = 5;//purple
     }
     else if (redColor > 250 && greenColor < 200 && blueColor < 200) {
       color = 6;//red
     }
     else if (redColor < 200 && greenColor > 250 && blueColor < 200) {
       color = 7;//green
     }
     else if (redColor < 200 /*&& greenColor < 200*/ && blueColor > 250) {
       color = 8;//blue
     }
     else {
       color = 0;//unknown
     }
    }
    
    void calibrate() {
     Serial.println("Calibrating...");
     Serial.println("White");//aim sensor at something white
     //set calibration vaues:
    
     digitalWrite(13, HIGH);
     delay(2000);
     digitalWrite(S2, LOW);
     digitalWrite(S3, LOW);
     redMin = pulseIn(sensorOut, LOW);
     delay(100);
     digitalWrite(S2, HIGH);
     digitalWrite(S3, HIGH);
     greenMin = pulseIn(sensorOut, LOW);
     delay(100);
     digitalWrite(S2, LOW);
     digitalWrite(S3, HIGH);
     blueMin = pulseIn(sensorOut, LOW);
     delay(100);
     Serial.println("next...");//aim sensor at something black
     digitalWrite(13, LOW);
     delay(2000);
     Serial.println("Black");
    
     //set calibration values:
     digitalWrite(13, HIGH);
     delay(2000);
     digitalWrite(S2, LOW);
     digitalWrite(S3, LOW);
     redMax = pulseIn(sensorOut, LOW);
     delay(100);
     digitalWrite(S2, HIGH);
     digitalWrite(S3, HIGH);
     greenMax = pulseIn(sensorOut, LOW);
     delay(100);
     digitalWrite(S2, LOW);
     digitalWrite(S3, HIGH);
     blueMax = pulseIn(sensorOut, LOW);
     delay(100);
     Serial.println("Done calibrating.");
     digitalWrite(13, LOW);
    }
    
    void printColor() {//print data
     Serial.print("R = ");
     Serial.print(redColor);
     Serial.print(" G = ");
     Serial.print(greenColor);
     Serial.print(" B = ");
     Serial.print(blueColor);
     Serial.print(" Color: ");
     switch (color) {
       case 1: Serial.println("WHITE"); break;
       case 2: Serial.println("BLACK"); break;
       case 3: Serial.println("ORANGE"); break;
       case 4: Serial.println("YELLOW"); break;
       case 5: Serial.println("PURPLE"); break;
       case 6: Serial.println("RED"); break;
       case 7: Serial.println("GREEN"); break;
       case 8: Serial.println("BLUE"); break;
       default: Serial.println("unknown"); break;
     }
    }
    
    void readColor() {//get data from sensor
     //red:
     digitalWrite(S2, LOW);
     digitalWrite(S3, LOW);
     redFrequency = pulseIn(sensorOut, LOW);
     redColor = map(redFrequency, redMin, redMax, 255, 0);
     delay(100);
    
     //green:
     digitalWrite(S2, HIGH);
     digitalWrite(S3, HIGH);
     greenFrequency = pulseIn(sensorOut, LOW);
     greenColor = map(greenFrequency, greenMin, greenMax, 255, 0);
     delay(100);
    
     //blue:
     digitalWrite(S2, LOW);
     digitalWrite(S3, HIGH);
     blueFrequency = pulseIn(sensorOut, LOW);
     blueColor = map(blueFrequency, blueMin, blueMax, 255, 0);
     delay(100);
    }
    
  • Simple Record and Playback 18 days ago

    I suggest visiting this website: https://www.arduino.cc/reference/en/language/variables/utilities/progmem/.

    Here is a piece of example code documenting read/write to PROGMEM I found there:

    /*
    Example Code
    The following code fragments illustrate how to read and write unsigned chars (bytes) and ints (2 bytes) to PROGMEM.
    */
    
    // save some unsigned ints
    const PROGMEM  uint16_t charSet[]  = { 65000, 32796, 16843, 10, 11234};
    
    // save some chars
    const char signMessage[] PROGMEM  = {"I AM PREDATOR,  UNSEEN COMBATANT. CREATED BY THE UNITED STATES DEPART"};
    
    unsigned int displayInt;
    int k;    // counter variable
    char myChar;
    
    
    void setup() {
      Serial.begin(9600);
      while (!Serial);  // wait for serial port to connect. Needed for native USB
    
      // put your setup code here, to run once:
      // read back a 2-byte int
      for (k = 0; k < 5; k++)
      {
        displayInt = pgm_read_word_near(charSet + k);
        Serial.println(displayInt);
      }
      Serial.println();
    
      // read back a char
      for (k = 0; k < strlen_P(signMessage); k++)
      {
        myChar =  pgm_read_byte_near(signMessage + k);
        Serial.print(myChar);
      }
    
      Serial.println();
    }
    
    void loop() {
      // put your main code here, to run repeatedly:
    
    }
    

    There is also an example for arrays and strings (which is very similar to what I used in this project). Again, I think you should find the above website helpful.

Add projectSign up / Login