Python Forum
3 easy questions for python programmers but 3 pain in the ass for me
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
3 easy questions for python programmers but 3 pain in the ass for me
#1
So quick run down; I am attempting to learn python so I can write simple programs to run my led matrix. I took Java 20+ years ago and when looking at the Python code it looks similar. But I don't remember any of it. Big Grin

Question 1: I have a mac address and it is in this form 00:AA:BB:CC:DD:EE. The code that I need to change is in this form { 0 x 00 : 0 x 00 : 0 x 00 : 0 x 00 : 0 x 00 : 0 x 00 }. Do I just remove 00 and replace it with letter/number combinations?

Question 2: In java you could write a small program. You could then call out for it another in another program, kinda like libraries in Python. In this case I have a script the uses an array and creates a 16 bit character. I would like to be able call out to that Python script within another, to me that would be cleaner.

Question 3: I would like for the Python script in question number 2 to be able to move from 0,0 to 128,0. So is there a way that I can do that?

Worse case scenario, I could create 256 individual arrays and then put them in order to give the appearance of movement but that just sounds awful.

Thanks for bearing with me, who would have thought at my age I would trying to learn a new language.
~Will
Reply
#2
I think I could help you grjmmr but I would need to see some code. Relatively speaking importing scripts is very easy in python depending upon where they are located. How exactly do you plan on running this LED matrix with python? Please give me more info such as what systems you plan to use for communication with the led matrix. Also why are you altering your BIA and what relevance does that have with running this LED matrix?

If you really want to make this simple I would suggest you dont pick up where you left off 20 years ago. Go buy yourself an arduino and start with youtube guide videos on basic programming of an arduino.
Reply
#3
{ 0 x 00 : 0 x 00 : 0 x 00 : 0 x 00 : 0 x 00 : 0 x 00 } would be for: 00:00:00:00:00:00
python equivalent would be 0x00:0xAA:0xBB:0xCC:0xDD:0xEE
or using netaddr:
import netaddr
mac_addr = netaddr.EUI('00-AA-BB-CC-DD-EE')
get netaddr here: https://pypi.org/project/netaddr/
Reply
#4
Thank you Larz60; I suspected that to be the Python equivalent; but could not find a forum or example on the web to back that up. I am assuming that was searching for the wrong key words.

Vysero, I should have been more clear. I am using a Anduino Uno and Ethernet Shield to drive a 16*16 matrix. I have 2 different scripts that I have been working with. One that checks Ethernet and Art-net connections, if they are both enabled and working, the matrix lights up with a preprogrammed pattern. This is what I needed the Mac address for. I have been having problems getting Jinx!; a led editing program to work. So I was using the Ethernet/Art-net script to trouble shoot it. The second script doesn't need the Mac address, it is just a series of animations. When I get home I will upload it. The reason I am trying to make everything so easy is that I am creating led banner for my band. It will be driven by Jinx! and Python scripts. I can't count on my lightman for the night knowing how to run everything so I am trying to make everything easy as possible.
Reply
#5
so essentially I am going to have a whole bunch of these scripts. Call out to them and have them move across a banner that is 128 leds across.

#include <avr/pgmspace.h> // Needed to store stuff in Flash using PROGMEM
#include "FastLED.h" // Fastled library to control the LEDs

// How many leds are connected?
#define NUM_LEDS 256

// Define the Data Pin
#define DATA_PIN 5 // Connected to the data pin of the first LED strip

// Define the array of leds
CRGB leds[NUM_LEDS];

// Create the array of retro arcade characters and store it in Flash memory
const long DigDug01[] PROGMEM =
{
0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0xcccccc, 0xcccccc, 0xcccccc, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
0x000000, 0x000000, 0x000000, 0xcccccc, 0xcccccc, 0xcccccc, 0xcccccc, 0xcccccc, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0xcccccc, 0xcccccc, 0xcccccc, 0xcccccc, 0xcccccc, 0xcccccc, 0xcccccc, 0xcccccc, 0x000000, 0x000000,
0x000000, 0xcccccc, 0xcccccc, 0xcccccc, 0xcccccc, 0xcccccc, 0xcccccc, 0xcccccc, 0xcccccc, 0xcccccc, 0xcccccc, 0xcccccc, 0x000000, 0x000000, 0x000000, 0x000000,
0x000000, 0x000000, 0x000000, 0x000000, 0x0066cc, 0x000000, 0x0066cc, 0x000000, 0x0066cc, 0x0066cc, 0x0066cc, 0x0066cc, 0xcccccc, 0xcccccc, 0xcccccc, 0x000000,
0x000000, 0xcccccc, 0xcccccc, 0xcccccc, 0x0066cc, 0x0066cc, 0x0066cc, 0x0066cc, 0x000000, 0x0066cc, 0x000000, 0x0066cc, 0x000000, 0x000000, 0x000000, 0x000000,
0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x0066cc, 0x0066cc, 0x0066cc, 0x0066cc, 0x0066cc, 0x0066cc, 0xcccccc, 0xcccccc, 0xcccccc, 0xcccccc, 0x000000,
0x000000, 0x000000, 0x000000, 0x0066cc, 0x0066cc, 0xcccccc, 0xcccccc, 0xcccccc, 0xcccccc, 0xcccccc, 0x000000, 0x000000, 0xff0000, 0x000000, 0x000000, 0x000000,
0x000000, 0x000000, 0xff0000, 0xff0000, 0x000000, 0xcccccc, 0xcccccc, 0xcccccc, 0xcccccc, 0xcccccc, 0xcccccc, 0x0066cc, 0x0066cc, 0xcccccc, 0x000000, 0x000000,
0x000000, 0xff0000, 0xff0000, 0xff0000, 0x0066cc, 0x0066cc, 0x0066cc, 0x0066cc, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0x000000,
0x000000, 0x000000, 0xff0000, 0xff0000, 0x000000, 0xcccccc, 0xcccccc, 0xcccccc, 0x0066cc, 0x0066cc, 0x0066cc, 0xcccccc, 0xcccccc, 0x000000, 0x000000, 0x000000,
0x000000, 0x000000, 0xcccccc, 0xcccccc, 0xcccccc, 0xcccccc, 0xcccccc, 0xcccccc, 0xcccccc, 0xcccccc, 0x000000, 0x000000, 0xff0000, 0x000000, 0x000000, 0x000000,
0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0xcccccc, 0xcccccc, 0x000000, 0x000000, 0x000000, 0xcccccc, 0xcccccc, 0x000000, 0x000000,
0x000000, 0x000000, 0xcccccc, 0xcccccc, 0xcccccc, 0xcccccc, 0x000000, 0xcccccc, 0xcccccc, 0xcccccc, 0xcccccc, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000
};

const long DigDug02[] PROGMEM =
{
0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0xcccccc, 0xcccccc, 0xcccccc, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
0x000000, 0x000000, 0x000000, 0xcccccc, 0xcccccc, 0xcccccc, 0xcccccc, 0xcccccc, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0xcccccc, 0xcccccc, 0xcccccc, 0xcccccc, 0xcccccc, 0xcccccc, 0xcccccc, 0xcccccc, 0x000000, 0x000000,
0x000000, 0xcccccc, 0xcccccc, 0xcccccc, 0xcccccc, 0xcccccc, 0xcccccc, 0xcccccc, 0xcccccc, 0xcccccc, 0xcccccc, 0xcccccc, 0x000000, 0x000000, 0x000000, 0x000000,
0x000000, 0x000000, 0x000000, 0x000000, 0x0066cc, 0x000000, 0x0066cc, 0x000000, 0x0066cc, 0x0066cc, 0x0066cc, 0x0066cc, 0xcccccc, 0xcccccc, 0xcccccc, 0x000000,
0x000000, 0xcccccc, 0xcccccc, 0xcccccc, 0x0066cc, 0x0066cc, 0x0066cc, 0x0066cc, 0x000000, 0x0066cc, 0x000000, 0x0066cc, 0x000000, 0x000000, 0x000000, 0x000000,
0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x0066cc, 0x0066cc, 0x0066cc, 0x0066cc, 0x0066cc, 0x0066cc, 0xcccccc, 0xcccccc, 0xcccccc, 0xcccccc, 0x000000,
0x000000, 0x000000, 0x000000, 0x0066cc, 0x0066cc, 0xcccccc, 0xcccccc, 0xcccccc, 0xcccccc, 0xcccccc, 0x000000, 0x000000, 0xff0000, 0x000000, 0x000000, 0x000000,
0x000000, 0x000000, 0xff0000, 0xff0000, 0x000000, 0x000000, 0x000000, 0xcccccc, 0xcccccc, 0xcccccc, 0xcccccc, 0x0066cc, 0x0066cc, 0xcccccc, 0x000000, 0x000000,
0x000000, 0xff0000, 0xff0000, 0xff0000, 0x0066cc, 0x0066cc, 0x0066cc, 0x0066cc, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0x000000,
0x000000, 0x000000, 0xff0000, 0xff0000, 0x000000, 0x000000, 0x000000, 0xcccccc, 0x0066cc, 0x0066cc, 0x0066cc, 0xcccccc, 0xcccccc, 0xcccccc, 0x000000, 0x000000,
0x000000, 0x000000, 0x000000, 0xcccccc, 0xcccccc, 0xcccccc, 0xcccccc, 0xcccccc, 0x000000, 0x000000, 0x000000, 0x000000, 0xff0000, 0x000000, 0x000000, 0x000000,
0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0xcccccc, 0xcccccc, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0xcccccc, 0xcccccc, 0xcccccc, 0xcccccc, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000
};


void setup() {
FastLED.addLeds<NEOPIXEL,DATA_PIN>(leds, NUM_LEDS); // Init of the Fastled library
FastLED.setBrightness(15);
}

void loop() {


// Put DigDug first frame
for(int passtime = 0; passtime < 8; passtime++) {

FastLED.clear();
for(int i = 0; i < NUM_LEDS; i++) {
leds[i] = pgm_read_dword(&(DigDug01[i]));
}

FastLED.show();
delay(250);


// Put DigDug second frame
FastLED.clear();
for(int i = 0; i < NUM_LEDS; i++) {
leds[i] = pgm_read_dword(&(DigDug02[i]));
}

FastLED.show();
delay(250);

}

This is based off of a script I found on Brainy Bits; giving credit where credit is due.
Reply
#6
FastLED.clear();
for(int i = 0; i < NUM_LEDS; i++) {
leds[i] = pgm_read_dword(&(DigDug01[i]));
}

FastLED.show();
delay(250);


// Put DigDug second frame
FastLED.clear();
for(int i = 0; i < NUM_LEDS; i++) {
leds[i] = pgm_read_dword(&(DigDug02[i]));
}
Reply
#7
mdjameel

Python uses : at the end of a conditional, not ;
you are not using indentation
this code will fail

also, you are not following forum rules about code tags, see BBCODE
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Deitel book "Python for Programmers" ricardian 7 23,160 May-12-2023, 01:33 PM
Last Post: snippsat
  creating simplex tableau pivot program easy or difficult for a beginner in Python? alex_0 2 2,583 Mar-31-2021, 03:39 AM
Last Post: Larz60+
  Python code Questions. TheDude 2 41,009 Jun-22-2020, 09:31 PM
Last Post: TheDude
  Questions re: my first python app (GUI, cross-platform, admin/root-level commands)? DonnyBahama 0 1,734 Feb-27-2020, 08:14 PM
Last Post: DonnyBahama
  What was my mistake in this Python code (easy)? voltman 4 3,453 Nov-19-2019, 09:58 PM
Last Post: snippsat
  This is a pain, is there a quicker way to do this? pcsailor 8 3,342 Nov-04-2018, 06:37 AM
Last Post: pcsailor
  easy to install python meterpreter windows juanb007 1 2,353 Oct-08-2018, 08:01 AM
Last Post: Larz60+
  IndentationError message could be confusing to new programmers insearchofanswers87 1 2,347 May-16-2018, 05:05 PM
Last Post: Larz60+
  Discord bot that asks questions and based on response answers or asks more questions absinthium 1 40,217 Nov-25-2017, 06:21 AM
Last Post: heiner55

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020