Giter Site home page Giter Site logo

centipede's People

Contributors

macegr avatar rocco83 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

glubbered rocco83

centipede's Issues

Flip (invert) an output pin value

I need to call digitalWrite (or maybe another new method) to say:
I don't care of the desired value, just read the current value and flip (invert) it.

AFAIK digitalRead can't be really used, as we speak about output pin, and in any case it will waste time for nothing.

Anyhow, the goal should be pretty much easy with the current code, as digitalWrite call WriteRegisterPin, which already read the port status and do bitwise operation.

In detail,

Currently, the WriteRegisterPin method take in input level to decide how to change the bit for the port, read, change and write the port back.

Seems to me that is possible to pass level with any int value, only 0 will have a different behavior than others.
level is taken, in example, from CS.digitalWrite without checking the value as well (AFAIK Arduino digitalWrite do the same just with uint8_t in place of int: https://github.com/arduino/ArduinoCore-avr/blob/9f8d27f09f3bbd1da1374b5549a82bda55d45d44/cores/arduino/wiring_digital.c#L156 ).
Eg i can set "6" as value, and it will be considered != 0.

Here the snippet

Centipede/Centipede.cpp

Lines 85 to 98 in 11bda08

void Centipede::WriteRegisterPin(int port, int regpin, int subregister, int level) {
ReadRegisters(port, subregister, 1);
if (level == 0) {
CSDataArray[0] &= ~(1 << regpin);
}
else {
CSDataArray[0] |= (1 << regpin);
}
WriteRegisters(port, subregister, 1);
}

So my idea is to

  1. Define a new int number which will invert the value (2?)
  2. Write the right bitwise operation that invert the bit value (xor, if I'm not wrong, https://stackoverflow.com/questions/47981/how-do-you-set-clear-and-toggle-a-single-bit as first google result)

So as logic it could be like:

  if (level == 2) { // this is just a sample, likely a switch/case would be more appropriate
    // ^= -> XOR bitwise
    // << -> left shift
    CSDataArray[0] ^= ~(1 << regpin);
  }
  • Would the feature make sense in CS library?
  • Do you think that a new function would be preferable, like flipDigitalWrite, or just having a new value passed to digitalWrite?
  • would make sense to check in WriteRegisterPin (or in digitalWrite or...) the value passed? And if so, how to properly report back to the user that garbage has been passed?

Thank you very much,
Daniele

Quick-fix errors in Centipede.cpp

A few of the references to the Wire library are outdated in language, generating a few errors. Updated:

  • Replace all Wire.send() to Wire.write()
  • Replace all Wire.receive() to Wire.read()

EDIT: undefined byte type seems to have been on my end.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.