Jump to content

Impulszähler


Gast ben_bienne

Recommended Posts

Hallo,

 

Ich habe ein Master Brick 2.0 und ein IO4 Bricklet. Damit möchte ich Impuls zählen. Ich habe angefangen ein script in Python zu schreiben. Bis jetzt kann ich damit nicht viel machen. Mein Proble ist folgendes

Wie kann ich mit einer loop solche Impuls zählen. Ich schaffe das nichts.

 

Hat jemanden so was schon probiert.

 

 

Link zu diesem Kommentar
Share on other sites

Moin.

 

Meinst du sowas in die Richtung?

 

#!/usr/bin/python3
# -*- coding: utf-8 -*-  

HOST = "127.0.0.1" # Change to your IP
PORT = 4223
UID = "uiD" # Change to your UID

import time

from tinkerforge.ip_connection import IPConnection
from tinkerforge.bricklet_industrial_digital_in_4 import IndustrialDigitalIn4

if __name__ == "__main__":
    ipcon = IPConnection() # Create IP connection
    idi4 = IndustrialDigitalIn4(UID, ipcon) # Create device object

    ipcon.connect(HOST, PORT) # Connect to brickd
    # Don't use device before ipcon is connected
    
    try:
        idi4.set_edge_count_config(1, IndustrialDigitalIn4.EDGE_TYPE_RISING, 1)
        ii = True
        while True:
            print('Edge count: {0}'.format(idi4.get_edge_count(0, ii)))
            time.sleep(0.5)
            ii = False
            
    finally:
        ipcon.disconnect()

 

Für weitere Details schau einfach mal hier: http://www.tinkerforge.com/de/doc/Software/Bricklets/IndustrialDigitalIn4_Bricklet_Python.html#industrial-digital-in-4-bricklet-python-api

 

Schöne Grüße

Link zu diesem Kommentar
Share on other sites

  • 2 weeks later...

Besten Dank für die Hilfe und Entschuldingung für die spätere Antwort.

 

Ich habe mein Zähler mit eine IO4 und 7 segment display gemacht.

 

 

#!/usr/bin/env python
# -*- coding: utf-8 -*-  

HOST = "localhost"
PORT = 4223
UID = "he6" # Change to your UID
dis = "kTk" # Change to your UID

DIGITS = [0x3f,0x06,0x5b,0x4f,
  0x66,0x6d,0x7d,0x07,
  0x7f,0x6f,0x77,0x7c,
  0x39,0x5e,0x79,0x71] # // 0~9,A,b,C,d,E,F

from tinkerforge.ip_connection import IPConnection
from tinkerforge.bricklet_io4 import IO4
from tinkerforge.bricklet_segment_display_4x7 import SegmentDisplay4x7

import time

if __name__ == "__main__":
    ipcon = IPConnection() # Create IP connection
    io = IO4(UID, ipcon) # Create device object
    sd4x7 = SegmentDisplay4x7(dis, ipcon) # Create device object

    ipcon.connect(HOST, PORT) # Connect to brickd
    # Don't use device before ipcon is connected

    # Set pin 1 to output low
    io.set_configuration(1 << 1, 'o', False)

    # Set pin 2 and 3 to output high
    io.set_configuration((1 << 2) | (1 << 3), 'o', True)

    try:
        io.set_edge_count_config(1, io.EDGE_TYPE_RISING, 1)
        ii = True
        while True:
            print('Edge count: {0}'.format(io.get_edge_count(0, ii)))
            compteur = format(io.get_edge_count(0, ii))
            compteur_string = "0" +"0" +compteur
            string = str(compteur_string)
            sub1 = int(string[0])
            sub2 = int(string[1])
            sub3 = int(string[2])

    if int(compteur) < 10 :
                segments = (DIGITS[0], DIGITS[sub1], DIGITS[sub2], DIGITS[sub3])
            sd4x7.set_segments(segments, 0, False)				
            elif int(compteur) >= 10:
	        sub4 = int(string[3])
			segments = (DIGITS[sub1], DIGITS[sub2], DIGITS[sub3], DIGITS[sub4])
                sd4x7.set_segments(segments, 0, False)
            elif int(compteur) >= 100:
                sub5 = int(string[4])
                segments = (DIGITS[sub2], DIGITS[sub3], DIGITS[sub4], DIGITS[sub5])
                sd4x7.set_segments(segments, 0, False)                    
            time.sleep(0.5)
            ii = False
    finally:
        ipcon.disconnect()

 

Schöne Grüsse

 

 

 

Link zu diesem Kommentar
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Gast
Reply to this topic...

×   Du hast formatierten Text eingefügt.   Formatierung jetzt entfernen

  Only 75 emoji are allowed.

×   Dein Link wurde automatisch eingebettet.   Einbetten rückgängig machen und als Link darstellen

×   Dein vorheriger Inhalt wurde wiederhergestellt.   Clear editor

×   Du kannst Bilder nicht direkt einfügen. Lade Bilder hoch oder lade sie von einer URL.

×
×
  • Neu erstellen...