Skillnad mellan versioner av "Grove - Line Finder"

Från Karlskrona Makerspace Wiki
Hoppa till: navigering, sök
 
(En mellanliggande version av samma användare visas inte)
Rad 58: Rad 58:
  
 
[[Category:Grove]]
 
[[Category:Grove]]
 +
[[Category:Grove-Sensor]]
 +
 +
[[Category:Kna-Wiki]]

Nuvarande version från 4 februari 2021 kl. 07.28

Grove - Line Finder

Line Finder-sensorn är tänkt att användas till linjeföljande robotar.

Kompatibilitet

  • Arduino
  • Raspberry Pi

Port

  • Digital

Exempelkod

Arduino

int signalPin =  3;    // connected to digital pin 3
void setup()   {
  pinMode(signalPin, INPUT); // initialize the digital pin as an output:
  Serial.begin(9600);  // initialize serial communications at 9600 bps:
}
// the loop() method runs over and over again,
// as long as the Arduino has power
void loop()
{
  if(HIGH == digitalRead(signalPin))
    Serial.println("black");
  else  Serial.println("white");  // display the color
  delay(1000);                  // wait for a second
}

Raspberry Pi

import time
import grovepi

# Connect the Grove Line Finder to digital port D7
# SIG,NC,VCC,GND
line_finder = 7

grovepi.pinMode(line_finder,"INPUT")

while True:
    try:
        # Return HIGH when black line is detected, and LOW when white line is detected
        if grovepi.digitalRead(line_finder) == 1:
            print ("black line detected")
        else:
            print ("white line detected")

        time.sleep(.5)

    except IOError:
        print ("Error")


Mer information

http://wiki.seeedstudio.com/Grove-Line_Finder/