Bluetooth (HC-06) with ATtiny85

Hi everyone,      I've been playing around with the HC-06 Bluetooth module for a while now and have had great success with it so far.  However, I have been using the Arduino Uno and Pro Mini, which have quite a few unused pins in my applications.  In order to downsize I'm trying to use the Atmel ATtiny85 chip.  I have used it many times in the past so I'm at least a bit familiar with its functions and limits.  For some reason I cannot get the Bluetooth module to work with the ATtiny85.  After many long and frustrating hours spent in vain, I decided to ask you all for help.  Does anyone know of any good tutorials or code for using the ATtiny85 with the HC-06 module?  It would be great if I could use the app Ardudroid to control the ATtiny85, but any help would be greatly appreciated.   Thanks ~Dudes

Topic by dudes   |  last reply


Can I control a robot with a wireless controller with bluetooth modules?

I'm working on a Hexapod right now, but I haven't found a way to control it wirelessly. I have tried working with nrf24L01 modules but just can't find a way for it to work.... Right now I have 2 HC-05 and 1 HC-06, can I do it? My plan is to control the hexapod (controlled by an Arduino) with a controller with another Arduino that has a joystick, along with 2 buttons to switch mode or rest mode. I'm still relatively new to Arduino so I have no idea how to search the way to control Arduinos using the 2 pins TXD and RXD. Also, which information can I send on these bluetooth modules (integer, boolean, etc)? I really appreciate if someone can help me start on how to use these things

Question by Shizen   |  last reply


How to reduce range on HC-05 BT module to 3 feet only?

I'm trying to design and build a rf shield to encase the hc-05 bluetooth module in order to reduce the range adjustably. For the first use I want to reduce the range to around 3 feet. Any tips?

Question by dmagryta124   |  last reply


Arduino servos not being supplied enough power by 9V battery?

Hey guys, I'm working on my first instructable which is an robotic snake which you control via the HC-06 bluetooth module and an arduino. I'm using an arduino bluetooth app on my smartphone, but this isn't the problem. There are three servos which I am supplying power to, two continuous rotation servos for movement and one ordinary servo. I'm powering it through a 9V battery thing I got off of the adafruit store, which has the plug that goes into the power supply. When I try to control it like this, the servos twitch and barely move. The ordinary one doesn't as far as I can tell. However, when I supply power through my computer cable, the bluetooth still works from my phone, and the servos go at an ordinary rate. I'm supplying the two continuous rotation servos and the normal one through the 5 volt pin, and the bluetooth module through the 3.3 volt one. Can anyone tell me why it isn't working, or an alternate technique of powering it?

Question by RedCthulu   |  last reply


Need help controlling two servos using arduino, bluetooth, and android.

Hi folks.  I am back.  I haven't been very active on here for the past several months, but I did move to a different continent.  Anyway, I need a little help from of those smart arduino folks out there.  I am looking for an app and arduino code to control two servos using an android device via Bluetooth.  There are a ton of instructables on controlling motors via Bluetooth, and there are also several tutorials on controlling one servo via Bluetooth, but what I want to know, is how to control two servos.  I am looking for something like this but able to control two servos.  I did try an app that uses an accelerometer to control two motors, but I want to be able to control them by a slide or nob.  If someone knows of a link that could be the solution to my problem I would be grateful for it. Any help would be greatly appreciated.  Thanks, th3_jungle_inv3ntor  -   actually I left the jungle :(

Topic by th3_jungle_inv3ntor   |  last reply


What does the "state" pin do on the HC-05 Bluetooth module?

Hi all, What is the function of the state pin on the HC-05 6-pin serial bluetooth module?

Question by dmagryta124   |  last reply


installing a DVD console in a 06 Malibu Maxx?

I have an OEM DVD RSE (Rear Seat Entertainment) console. It is for a 2006 Chevy Malibu Maxx LTZ. The console I have in my car is without the DVD component. I see 4 holes to bolt it into the center. As I will have to remove the one in my car and replace it with the new GM part, will I have to take the seats out? Anything special I should do first?

Question by  


How to use Bluetooth Module - HC-05 Device as audio receiver?

I want to connect Bluetooth Module - HC-05 (or HC-06) to my home theater to receive stereo audio signal from laptop. please give me the full guidelines.

Question by smandal13   |  last reply


How to power servo without driver/arduino?

Hi, I'm trying to make a servo motor spin without using a driver or micro controller, I just want to power it directly. It doesn't need to move a specific distance, or be precise. How would I wire this up? The idea is to power it on by using a HC-05 Bluetooth module, either directly, or by optocoupler. It would have to trigger the servo on whenever a Bluetooth device that has already been paired connects to the HC-05 module (in wireless range), and then off when a Bluetooth device disconnects (out of range). My idea is to use an app that automatically plays an audio file through the HC-06 when it connects (this app already exists), and that audio file happens to be the correct frequency to act as a PWM signal. Is this even possible?

Question by dmagryta124   |  last reply


FTP Hassels

I've been trying forever to get my FTP server up and running properly, to start, this is what I have:Filezilla running as a service, port 21 and also some randomly selected listening ports have been opened on modem/router, all the user accounts have been set up properly, and I can confirm that it works from LAN side of the network. I have a dynamic ip so I had to go the no-ip.com way, but it seems to work pretty good giving me a hostname.myftp.org address.I've had 4-5 people try it that I want to have access to it, and only one of them can actually get on, but he was using a different ftp client that I had never heard of, the other people were trying in mac os x or with filezilla's client software. Here is what I get:(000037) 11/7/2008 0:20:06 AM - (not logged in) (12.216.139.84)> Connected, sending welcome message...(000037) 11/7/2008 0:20:06 AM - (not logged in) (12.216.139.84)> 220-FileZilla Server version 0.9.27 beta(000037) 11/7/2008 0:20:06 AM - (not logged in) (12.216.139.84)> 220-Punkguyta's Drop Zone(000037) 11/7/2008 0:20:06 AM - (not logged in) (12.216.139.84)> 220 Please go easy, my upload isn't all that great, thx =P(000037) 11/7/2008 0:20:06 AM - (not logged in) (12.216.139.84)> USER downloads(000037) 11/7/2008 0:20:06 AM - (not logged in) (12.216.139.84)> 331 Password required for downloads(000037) 11/7/2008 0:20:06 AM - (not logged in) (12.216.139.84)> PASS *********(000037) 11/7/2008 0:20:06 AM - downloads (12.216.139.84)> 230 Logged on(000037) 11/7/2008 0:20:06 AM - downloads (12.216.139.84)> PWD(000037) 11/7/2008 0:20:06 AM - downloads (12.216.139.84)> 257 "/" is current directory.(000037) 11/7/2008 0:20:06 AM - downloads (12.216.139.84)> TYPE I(000037) 11/7/2008 0:20:06 AM - downloads (12.216.139.84)> 200 Type set to I(000037) 11/7/2008 0:20:06 AM - downloads (12.216.139.84)> PASV(000037) 11/7/2008 0:20:07 AM - downloads (12.216.139.84)> 227 Entering Passive Mode (209,240,120,189,19,146)(000037) 11/7/2008 0:20:07 AM - downloads (12.216.139.84)> LIST(000037) 11/7/2008 0:20:17 AM - downloads (12.216.139.84)> 425 Can't open data connection.(000037) 11/7/2008 0:20:40 AM - downloads (12.216.139.84)> disconnected.This is what I get with everyone, but my friend that could get on, it worked fine for him and the speed was great. I want to pull my hair out because I've googled over and over, and I'm following the directions, as retardedly easy as they are, and everything should just work correctly, I have filezilla setup to be a passive server and to retreive an external ip address from a url, and they have a default site that seems to also work okay. I'm just wondering if this is the problem, because I'm also running the no-ip dns software side by side? I don't think it matters though.Oh yeah, and I also have it setup for custom port ranges 5000-5100, so unless I plan on having even 80 or more users at a time, that should be a wide enough range. Also, don't use external ip for local network connections is checked.It seems so simplistic to me, and being able to access it locally fine, and seeing at least one other person get on it made me happy, but is there maybe something wrong in the configuration on their end(s)??Thank you guys if you can help me hit this dumb problem in the head.

Topic by Punkguyta   |  last reply


A Tutorial for making an Arduino Shield.

Hi Folks, I've put together a tutorial on how to make an Arduino shield using EAGLE. It can be found here: http://aaroneiche.com/2010/06/24/a-beginners-guide-to-making-an-arduino-shield-pcb/

Topic by aarone 


Digital Holga Project Featured On Peta Pixel

I was asked a week ago to do my digital holga project for PetaPixel and they just posted the project up there check it out! http://www.petapixel.com/2010/06/30/how-to-convert-a-holga-lens-for-your-dslr-for-toy-camera-fun/

Topic by frenzy 


RC circuit with a transistor and an LED Answered

Http://tronixstuff.files.wordpress.com/2010/06/pic23.jpg Could someone please explain how this circuit works? I understand that while the capacitor is charging, current flows to the base of transistor and so the LED lights, but I can't figure out the discharging. P.S. I assume that by building this circuit I'll get an LED blinking constantly?

Question by MaracKoMarac   |  last reply


Help to make 12V Car adapter for motorcycle

Not sure if right forum or not but wondering if someone could give me a hand to make something similar to this http://cgi.ebay.ca/YAMAHA-04-05-06-07-08-yzf-R1-POWER-PLATE-phone-charger-/250699849710?pt=Motorcycles_Parts_Accessories&hash;=item3a5ee01fee#ht_5400wt_1141 I know the parts could be bought for a lot less but just wondering what would be the best way to do this. Thanks,

Topic by MacGeek83   |  last reply


Arduino Bluetooth to Visual Forms

Hey folks I hav a problem: I am trying to make a GUI in visual forms which displays Data received from an Arduino via Arduino sent with a HC-06 Blutooth module, the data is a 10 cell integer array which should be displayed in 10 textboxes. my problem is how do I retrieve the data from the computer's bluetooth in Visual Forms/Studio. thank you for your help

Topic by Red-Fox   |  last reply


what color is good for lucid dreaming? Answered

I want to make a lucid dreaming mask so that i could lucidly dream, i already have the program written down for the timing, but I need to know what color led's to use. here is a link about what i would like: http://blog.makezine.com/2008/06/19/how-to-build-a-lucid-drea/. i just really need to know what color would induce lucid dreaming the easiest. thanks

Question by techno guy   |  last reply


Urgent need of help: Why does Arduino car works with cable but not with external power supply??

I made a arduino car robot with arduino uno (shields on it), sharp IR-sensor, 2DC motors, 4AA battry and 2 limited switch. When I connect the arduino with the cable, it works fine! all the functions work and I don't see any errors. However once I try to let it work through external power supply (4aa) it doesn't work at all. The power light lights up but that's it. I think I would need to use resistor for each limited switch but I have no clue which resistors I should use and I am not certain if it will solve this problem either. Please help me because I am getting so hopeless. Thank in advance. PS - I tried this method but it seems like it's not working at all  V = R * I, or solved for R, R = V / I R = 6 volts / 0.030 amps R = 200 ohms --> 220 resistor  my breadboard are based on this fritzing sketch https://killerrobotics.files.wordpress.com/2015/06/robot-part-1_bb.png  https://killerrobotics.files.wordpress.com/2015/06/robot-part-2_bb.png

Question by RJK6   |  last reply


Trojan horse for macs in the wild

Uhoh.A trojan horse for MACS has been spotted: http://www.theregister.co.uk/2008/06/23/mac_trojan/It can take screenshots, log keystrokes, or (and here's the scariest bit) take pictures of you while on your computer through the built-in camera. Yikes!Be careful, all you apple users! You have a security concern to worry about ("a" trojan to worry about. As opposed to windows users...) ! Stay off Limewire and iChat. Lock your ports at night, and don't chat with strangers!

Topic by Lithium Rain   |  last reply


Replacement for this FET?

Okay... so long story short, i have this little transistor that i need the non-surface mounted version of. The part # is PHD3055E. I can only find the datasheet, And can't find it anywhere for sale. So i thought i'd come here and ask, Any ideas on what could replace this? Here's the datasheet in the google docs viewer. http://docs.google.com/viewer?a=v&q;=cache:huahl6K3DFkJ:www.datasheetcatalog.org/datasheet/philips/PHP_PHD3055E-06.pdf+PHD3055E&hl;=en≷=us&pid;=bl&srcid;=ADGEESg3724yaKjv666t2rqjyyXVjvQp5HpfKIXr3723cJt4Y_bqPXypg_oySVo3Q9eOgiMBHIG4zDYsHVk73N0whYfHI3PTtv8kTeA_FzIxSWhNnkzgniEWSIQLls8aeQVgmyBDhZyI&sig;=AHIEtbRm4XdPQEc-wzTiPkqsGwSO1qblnA

Question by ReCreate 


Iphone, extension cable?

Hello I´m trying to use a usb extension cable to charge my iphone 3Gs. But it´s not working, I get an error.? I use a usb extension cable to connect to the charger and the iphone cable on the female port. www.ace-plus.com/product/data_c/usb_extension_cable.jpg Do I have to buy this kind of cable? www.geardiary.com/wp-content/uploads/2009/06/iphone-dock-extender-cable.jpg Does any Iphone 3Gs user have this problem? EDIT: If I use a shilded usb-extender it works, but why not the other...naked one?

Question by Popstickal   |  last reply


music shield V2 with bluetooth can't receive message

I wnat to receive messages from phone and add variable to change songs. Why the program can't receive message.Can't enter the while loop when I send message. How can I change the program? (mega2560,HC-06 Bluetooth and music shield V2) music shield V2 must include Music_Shield-master library #include #include #include #include #include SoftwareSerial BTSerial(10, 11); // RX | TX char a; int i=0; void setup() {    Serial.begin(9600);             BTSerial.begin(9600);  // HC-06 current bound rate (default 9600)                         player.begin();                      //will initialize the hardware and set default mode to be normal.    player.setPlayMode(PM_REPEAT_ONE); //set mode to repeat playing a song    player.playOne("1.aac");          //play a song with its name                 player1.begin();                      //will initialize the hardware and set default mode to be normal.    player1.setPlayMode(PM_REPEAT_ONE);    player1.playOne("2.aac");         player.digitalControlEnable();                        Serial.println("Let's DEMO");         } void loop() {                if(i%2==0)         {           player.play();           Serial.println("player play");           delay(5000);         }         else         {           player1.play();           Serial.println("player1 play");           delay(5000);         }       //////////bluetooth         while(BTSerial.available())         {             byte inByte = BTSerial.read();             a=inByte;                 }                 if(a=='g')         {              Serial.print("receive g message");              i++;              //delay(1000);         }         if(a=='t')         {              Serial.print("receive t message");              i++;              //delay(1000);         }               }

Question by 竣凱詹 


v-i curve tracer? waiting for the best answerer Answered

i want to build this simple v-i curve tracer circuit at the page.. http://freecircuitdiagram.com/2008/09/06/voltage-currentvi-curve-tracer/ on the same page, they have shown different traces of diodes,capacitors, transistors... what i am thinking is that if i connect this tracer to the pins of any ic, would this damage the ic or show v-i trace of that ic or of  those two pirticular pins to which i connected the probes?

Question by hussainb   |  last reply


Bio-fuels from pvc, etc. Some neat advances being made in the bio-fuel areas:

2002 articlehttp://www.brdisolutions.com/news/NewsletterArchive/dec2002.aspThis year....http://biodieselmagazine.com/article.jsp?article_id=1504&q;=&page;=allAnd then we have this:http://ec.europa.eu/energy/res/legislation/doc/biofuels/contributions/industry/waterman.pdfand a few articles from WIRED:http://www.wired.com/science/discoveries/news/2004/09/64862http://www.wired.com/science/discoveries/news/2004/06/63699plus: http://www.europabio.org/white_biotech.htmhttp://lib.wmrc.uiuc.edu/enb/?cat=2Info on Styrene: http://www.osha.gov/SLTC/styrene/

Topic by Goodhart   |  last reply


Altec Lansing Speaker Control Pod ?

Not sure if this is the right place to ask but im trying to build a new Controller ( Volume up, down, Bass, power, ect) for my speakers. Old pod broke and got thrown out some time ago and company stoped making parts. Im not a tech person but ill put down everything i know about the controller in hopes one can help me. Model was MX6021, It used 8-pin mini-DIN cable...It had volume +/-, Bass +/-, and most importantly it switched on the subwoofer which the speakers connect to. I really have no idea where to start on buying electronic parts..Thanks in advanced if anyone replys.. Here are some links for pictures.. vmart. pk/images/detailed/9/mx6021_5.jpg glidemagazine. com/hiddentrack/wp-content/uploads/2012/06/Controller.jpg images.hardwarezone. com/upload/files/2010/01/67921c4ed1.jpg

Question by shagggggggy   |  last reply


High power LED brand recommendations?

I have an idea for an Arduino-controlled LED floor lamp and am interested in subjective information about the different brands of high power LEDs--pros and cons, the color and quality of the light, availability of heatsinks, mounting brackets, drivers, durability, price and so on.  Sparkfun sells Luxeon so it's tempting to just go with that, but I don't want to just go with that and find out something else was better.  I don't have a definite design yet just in the daydream stages, I want to be able to dim and brighten, turn individual LEDs on and off, be able to adjust the quality of light from warm to cool, I'm thinking white as a basis plus some RGB LEDs or other color leds to tweak the color, but the white light will do the heavy lifting, probably with some opaque white plastic or glass to mix and diffuse the light from all of the LEDs.  I found a few articles, but they're a few years old, or not exactly relevant (e.g. comparison of flashlights using these LEDs). www.lighthound.com/Fenix-Cree-Luxeon-Rebel-LED-Flashlight-Comparison-Chart_ep_53-1.html www.candlepowerforums.com/vb/showthread.php?221524-cree-vs-luxeon ledflashlights.blogspot.com/2011/06/cree-versus-luxeon.html ledsreview.com/articles/209/

Topic by cdslashetc   |  last reply


CLOCKS!!! how to make a.... very powerful clock?

Hey, I'm new on here but realllyyy need some help in this as I have a limited technological background. Basically I have a project in which have two digital displays, each one displaying either the time, in minutes or the hour (two digits per display). Now what I want to do with these is effectively attach these on to the hands of an analogue clock, so that when the hands spin round, the time is displayed. For example when the minutes hand is at the quarter past mark, the display will read 15 and when the hour hand is at the bottom the other display will read 06. So I have the designs ready for this clock (including counterweights and whatnot) but I just need a very powerful clock movement, or gearing system that will enable me to turn a couple of heavy clock hands, I have seen online you can but high torque movements which at the moment is my best bet, but i cant imagine it will work very well to be honest. I would really appreciate any response or something to point in the right direction as I'm very open minded and if the issue is solved, I will be sure to put up instructions on how this clock was made. Thanks for reading. Josh

Question by joshblee23   |  last reply


DIY continuous rotating servo motor for cat toy?

I'm trying to make a cat toy for my cat based somewhat loosely off of a toy called the fling-ama-string. http://www.youtube.com/watch?v=rwB4kmTd440&feature;=related I have one and he seems to like it but since it only moves vertically I've noticed that he gets bored quite quickly. However, when I lay the fling-ama-string horizontally on my table and the string runs over the edge of the table he plays with it a lot longer. My idea was similar to something like this: http://newswatch.nationalgeographic.com/2011/06/15/the-cheetah-run/ Which seems to have a motor running a line from across one side of a field to the other. I obviously do not need one as heavy duty as this but I feel like if I were to rig this around the leg of a few pieces of furniture and let my cat run around chasing the lure a few times a week he'd really enjoy it. My issue is what kind of motor do I need and how difficult is this going to be to set up? Also, I'd like to spend less than $50 on all the parts for this but seeing as how the motor itself might be somewhat pricey I can understand if it goes over my initial cap. If anyone has any ideas I'd really appreciate it!

Question by lasingparuparo   |  last reply


What is this website: Dungmusic . Answered

I googled my email address today and the top entry was this: 09/05/2011 05:09:07 Outgoing Emailer Started09/05/2011 05:09:16 ...http://dungmusic.info/logs/eslog.txt ...... 06:09:53 Successfully sent:(1955) MY EMAIL ADDRESS.com/r/n09/05/2011 ... I searched for this company but every site seems to be just pages of this type of thing: hiphophanger@gmail.com09/14/2011 22:09:25 Successfully sent:(964) hiphophanger@gmail.com/r/n09/14/2011 22:09:25 Trying to send:(965) kgmartyn@worldonline.co.uk09/14/2011 22:09:25 Successfully sent:(965) kgmartyn@worldonline.co.uk/r/n09/14/2011 22:09:25 Trying to send:(966) flanaganpaddy1@hotmail.com09/14/2011 22:09:25 Successfully sent:(966) flanaganpaddy1@hotmail.com/r/n09/14/2011 22:09:25 Trying to send:(967) atyourdoor05@yahoo.co.uk09/14/2011 22:09:25 Successfully sent:(967) atyourdoor05@yahoo.co.uk/r/n09/14/2011 22:09:25 Trying to send:(968) debiatfinalphase@msn.com09/14/2011 22:09:25 Successfully sent:(968) debiatfinalphase@msn.com/r/n09/14/2011 22:09:25 Trying to send:(969) princess_raisin@hotmail.co.uk09/14/2011 22:09:25 Successfully sent:(969) princess_raisin@hotmail.co.uk/r/n09/14/2011 22:09:25 Trying to send:(970) abshiro123@yahoo.co.uk09/14/2011 22:09:25 Successfully sent:(970) abshiro123@yahoo.co.uk/r/n09/14/2011 22:09:25 Trying to send:(971) scobling1979@hotmail.com09/14/2011 22:09:25 Successfully sent:(971) scobling1979@hotmail.com/r/n09/14/2011 22:09:25 Trying to send:(972) littlepeople@gillydobson.plus.com09/14/2011 22:09:26 Successfully sent:(972) littlepeople@gillydobson.plus.com/r/n09/14/2011 22:09:26 Trying to send:(973) s I'm just curious: what is it? Thanks.

Question by FriendOfHumanity   |  last reply


Momentary switch to Bluetooth

I'd like to make a number of smallish (say 0.75x1x2 inches) battery-powered Bluetooth boxes each of which connects to a momentary switch, and sends an RFCOMM or HID signal via Bluetooth on depression and another on release, and which will to communicate with an Android device. Because I want to make several of these, I want something super cheap and super simple to make.  (The purpose is to make a simple wireless touch detection system for foil and epee fencing. Without on-target detection, it's not going to be great, but it will be an improvement over refereeing fully dry bouts, since at least one will have proper impact and lockout timing.) Here are options I've been thinking about: 1. One thing that would *almost* do the job is to buy one of those $3-5 ebay Bluetooth phone camera remotes, and just wire my switch to it. The only problem is that according to the ads I've seen, these Bluetooth phone camera remotes go to sleep in 2-10 minutes when paired (exact timing seems to depend on the model), and I would really rather avoid this (the 10 minutes is almost acceptable). If anybody knows of a way of keeping them paired and awake for a longer period of time (say, 15 minutes or permanently), I would love to hear. This would be the cheapest and simplest solution, and it comes with a case and battery (some units are even USB chargeable).  2. On the other extreme of the price range, I happen to have some extra Brainlink modules with an atxmega and an RN-42 module inside, and it wouldn't take long to customize the firmware to do the job. But the modules sell for $39 (though sometimes on sale for $20), and that seems overkill for something so simple. And they are a touch larger than I like (about 3 inches diameter, and an awkward shape). 3. Another option might be to use a cheap serial Bluetooth module without additional hardware, and wire the switch directly to CTS. Unfortunately, I don't think the cheap HC-06 modules support CTS, though I think the HC-07 does support it (but I don't know if I can access it as it's probably not one of the pins on the header). Moreover, there are two unanswered questions on Stackexchange on how to access CTS/RTS status from Android, so this might require using a laptop as the base station (which isn't ideal). 4. A very cheap microcontroller with a UART (or just bit-banging) plus a cheap Bluetooth module. This increases the complexity of the project, but might be the way to go. More specific recommendations are welcome, as I have no experience with the hardware side of dealing with a microcontroller (on the software side, I've spent a fair amount of time tweaking the firmware of the Brainlink unit).

Topic by arpruss 


Help With arduino Tic tac toe

//This program is a 2 human player tic tsc toe//Created on August 26, 2008 int val; int O; int val2; int playerTurn = 1; int spotOne = 01; // These are the varibles for each possible spot on the grid int spotTwo = 02; int spotThree = 03; int spotFour = 04; int spotFive = 05; int spotSix = 06; int spotSeven = 07; int spotEight = 8; int spotNine = 9; int Player1 = 00; // these will be used to have the players choose their spot on the grid int Player2 = 11; void setup () { Serial.begin(9600); (playerTurn == 1); Serial.println ("Welcome to the two player tic tac toe game."); Serial.println ("Players will take turns putting their choices into the terminal by number."); Serial.println ("Each free space on the grid will have a number on it from 1 to 9."); Serial.println ("Player one will be an 0 and player two will be an 11"); Serial.println ("The first person you get 3 of theor symbols in a row wins"); delay (5000); }void loop (){Serial.println(val);Serial.print (spotOne);Serial.print (" !");Serial.print (spotTwo);Serial.print (" !");Serial.println (spotThree); //First LineSerial.print (spotFour);Serial.print (" !");Serial.print (spotFive);Serial.print (" !");Serial.println (spotSix); //line 2Serial.print (spotSeven);Serial.print (" !");Serial.print (spotEight);Serial.print (" !");Serial.println (spotNine);Serial.print ("It is player ");Serial.print (playerTurn);Serial.println ("'s turn, enter your selection");delay (500); if (playerTurn = 1){ if (Serial.available()) { (val = Serial.read()); if (val == 49){ if (spotOne != 11 || 0){ (spotOne == 11); (playerTurn = 2); } if (val == 50){ if (spotTwo != 11 || 0){ (spotTwo == Player1); (playerTurn = 2); } if (val == 51){ if (spotThree != 11 || 0){ (spotThree == Player1); (playerTurn = 2); } if (val == 52){ if (spotFour != 11 || 0){ (spotFour == Player1); (playerTurn = 2); } if (val == 53){ if (spotFive != 11 || 0){ (spotFive == 11 ); (playerTurn = 2); } if (val == 54){ if (spotSix != 11 || 0){ (spotSix = Player1); (playerTurn = 2); } if (val == 55){ if (spotSeven != 11 || 0){ (spotSeven = Player1); (playerTurn = 2); } if (val == 56){ if (spotEight != 11 || 0){ (spotEight = Player1); (playerTurn = 2); } if (val == 57){ if (spotNine != 11 || 0){ (spotNine = Player1); (playerTurn = 2); }}}}}}}}}} } } if (playerTurn = 2){ if (Serial.available()) { (val = Serial.read()); if (val == 49){ (spotOne == 0); (playerTurn = 1); } if (val == 50){ if (spotTwo != 11 || 0){ (spotTwo = Player2); (playerTurn = 1); } if (val == 51){ if (spotThree != 11 || 0){ (spotThree = Player2); (playerTurn = 1); } if (val == 52){ if (spotFour != 11 || 0){ (spotFour = Player2); (playerTurn = 1); } if (val == 53){ if (spotFive != 11 || 0){ (spotFive = Player2); (playerTurn = 1); } if (val == 54){ if (spotSix != 11 || 0){ (spotSix = Player2); (playerTurn = 1); } if (val == 55){ if (spotSeven != 11 || 0){ (spotSeven = Player2); (playerTurn = 1); } if (val == 56){ if (spotEight != 11 || 0){ (spotEight = Player2); (playerTurn = 1); } if (val == 57){ if (spotNine != 11 || 0){ (spotNine = Player2); (playerTurn = 1); }}}}}}}}} } }} Can anyone help me with this program. I cant quite get it to work properly. You can make changes anywhere.

Topic by sotsirh194   |  last reply


Where did I go wrong [Batch]?

What is wrong with this code? I have it open this program: @echo off mode 18,4 title Actions :1 cls echo (B)           (Y) echo   (A)       (X) echo. set /p a= echo %a%> link.txt goto 1 And this prgram is supposed to read the input. Basically, the first one sends a message to a TXT file. Then this program picks up the message from the TXT file and turns it into a variable. @echo off title Whack-a-Mole set a=10 set mole=0 set time=0 set timeend=0 :Start cls set /a a=%a%-1 echo This game uses the "Actions" gamepad unit. echo. echo. echo Hit the most moles to win! echo. echo Game starts in %a% seconds. ping localhost -n 2 > nul if %a% equ 0 goto Game goto Start :Game if exist Actions.bat start Actions.bat cls echo Press "A" on the gamepad unit to swing your bat. Press "B" to stop. echo. if not exist link.txt ( echo The file "link.txt" could not be found. This game cannot be played without it. ping localhost -n 4 > nul ) if not exist Actions.bat ( echo The file "Actions.bat" could not be found. This game cannot be played without it. ping localhost -n 4 > nul ) ping localhost -n 4 > nul :GameBegin cls echo Ready... ping localhost -n 4 > nul cls echo GO! ping localhost -n 2 > nul :Mole1 cls set /a time=%random%/7000 echo Reaction Time:%timeend% echo Moles Hit:%mole% echo. echo [__][__][__][__] echo   [__][__][__][__] echo     [__][__][__][__] ping localhost -n 2 > nul set a=< link.txt echo 00> link.txt if /i "%a%"=="a" goto gameover if /i "%a%"=="b" goto gameover if /i "%a%"=="00" goto gameover set a= ping localhost -n %time% > nul goto Mole2 :Mole2 cls set /a time=%random%/7000 echo Reaction Time:%timeend% echo Moles Hit:%mole% echo. echo [__][__((O.O))_] echo   [__][__/:_][__] echo     [__][/ [__][__] ping localhost -n 2 > nul set a=< link.txt echo 00> link.txt if /i "%a%"=="a" ( set /a mole=%mole%+1 goto Time ) if /i "%a%"=="b" goto gameover if /i "%a%"=="00" goto gameover set a= ping localhost -n %time% > nul goto gameover :Time set timestart=%time:~2% set timeend=%timestart:~4,2% if /i %timeend% equ 01 set timeend=1 if /i %timeend% equ 02 set timeend=2 if /i %timeend% equ 03 set timeend=3 if /i %timeend% equ 04 set timeend=4 if /i %timeend% equ 05 set timeend=5 if /i %timeend% equ 06 set timeend=6 if /i %timeend% equ 07 set timeend=7 if /i %timeend% equ 08 set timeend=8 if /i %timeend% equ 09 set timeend=9 set /a timeend= %timeend%+2+%random:~1,1% if %timeend% geq 60 ( goto gameover ) goto Mole1 :gameover cls echo You got %mole% moles. echo Your fastest time was %timeend%. echo. echo Type in "B" on the gamepad unit to go back to the main menu. :input set a=< link.txt if /i "%a%"=="b" goto Start goto input It may look kinda wierd here, but that's because of instructables, not me. Anyways, it goes through the animations and doesn't even notice that there are any IF commands. Where did I go wrong? EDIT: Figured it out. Corrected: SET /P a=< link.txt Forgot the /p!

Question by TheBatchies   |  last reply


Write output on registery inside ESP8266

Could any one help me please? I have the following code to make MODBUS tcp/ip(its work good) the other issue in the code is ultrasonic sensor (trig on D1& echo on D2 and output distance on serial port)I want to write distance on one of memory register say (3). I use the command "digitalWrite(distance, MBHoldingRegister[3] )" its fail then I use analogWrite also fail what's the solution?#include #define trigPin D1#define echoPin D2#define analog_output D5float distance;long duration;int dataIn;int m = 0;int h = 0;int t = 0;const char* ssid = "MH_Ext";const char* password = "74375325";int ModbusTCP_port = 502;//////// Required for Modbus TCP / IP /// Requerido para Modbus TCP/IP /////////#define maxInputRegister 20#define maxHoldingRegister 20#define MB_FC_NONE 0#define MB_FC_READ_REGISTERS 3 //implemented#define MB_FC_WRITE_REGISTER 6 //implemented#define MB_FC_WRITE_MULTIPLE_REGISTERS 16 //implemented// MODBUS Error Codes//#define MB_EC_NONE 0#define MB_EC_ILLEGAL_FUNCTION 1#define MB_EC_ILLEGAL_DATA_ADDRESS 2#define MB_EC_ILLEGAL_DATA_VALUE 3#define MB_EC_SLAVE_DEVICE_FAILURE 4// MODBUS MBAP offsets//#define MB_TCP_TID 0#define MB_TCP_PID 2#define MB_TCP_LEN 4#define MB_TCP_UID 6#define MB_TCP_FUNC 7#define MB_TCP_REGISTER_START 8#define MB_TCP_REGISTER_NUMBER 10byte ByteArray[260];unsigned int MBHoldingRegister[maxHoldingRegister];//////////////////////////////////////////////////////////////////////////WiFiServer MBServer(ModbusTCP_port);void setup() {pinMode(14, OUTPUT);pinMode(trigPin, OUTPUT);pinMode(echoPin, INPUT);Serial.begin(9600);delay(100) ;WiFi.begin(ssid, password);delay(100) ;Serial.println(".");while (WiFi.status() != WL_CONNECTED) {delay(500);Serial.print(".");}MBServer.begin();Serial.println("Connected ");Serial.print("ESP8266 Slave Modbus TCP/IP ");Serial.print(WiFi.localIP());Serial.print(":");Serial.println(String(ModbusTCP_port));Serial.println("Modbus TCP/IP Online");}void loop() {distance = getDistance();Serial.println(distance);delay(1000);// Check if a client has connected // Modbus TCP/IPWiFiClient client = MBServer.available();if (!client) {return;}boolean flagClientConnected = 0;byte byteFN = MB_FC_NONE;int Start;int WordDataLength;int ByteDataLength;int MessageLength;// Modbus TCP/IPwhile (client.connected()) {if(client.available()){flagClientConnected = 1;int i = 0;while(client.available()){ByteArray[i] = client.read();i++;}client.flush();///// code here --- codigo aqui///////// Holding Register [0] A [9] = 10 Holding Registers Escritura///////// Holding Register [0] A [9] = 10 Holding Registers Writing/// Enable Output 14digitalWrite(14, MBHoldingRegister[14] );digitalWrite(distance, MBHoldingRegister[12] );//// end code - fin//// rutine Modbus TCPbyteFN = ByteArray[MB_TCP_FUNC];Start = word(ByteArray[MB_TCP_REGISTER_START],ByteArray[MB_TCP_REGISTER_START+1]);WordDataLength = word(ByteArray[MB_TCP_REGISTER_NUMBER],ByteArray[MB_TCP_REGISTER_NUMBER+1]);}// Handle requestswitch(byteFN) {case MB_FC_NONE:break;case MB_FC_READ_REGISTERS: // 03 Read Holding RegistersByteDataLength = WordDataLength * 2;ByteArray[5] = ByteDataLength + 3; //Number of bytes after this one.ByteArray[8] = ByteDataLength; //Number of bytes after this one (or number of bytes of data).for(int i = 0; i < WordDataLength; i++){ByteArray[ 9 + i * 2] = highByte(MBHoldingRegister[Start + i]);ByteArray[10 + i * 2] = lowByte(MBHoldingRegister[Start + i]);}MessageLength = ByteDataLength + 9;client.write((const uint8_t *)ByteArray,MessageLength);byteFN = MB_FC_NONE;break;case MB_FC_WRITE_REGISTER: // 06 Write Holding RegisterMBHoldingRegister[Start] = word(ByteArray[MB_TCP_REGISTER_NUMBER],ByteArray[MB_TCP_REGISTER_NUMBER+1]);ByteArray[5] = 6; //Number of bytes after this one.MessageLength = 12;client.write((const uint8_t *)ByteArray,MessageLength);byteFN = MB_FC_NONE;break;case MB_FC_WRITE_MULTIPLE_REGISTERS: //16 Write Holding RegistersByteDataLength = WordDataLength * 2;ByteArray[5] = ByteDataLength + 3; //Number of bytes after this one.for(int i = 0; i < WordDataLength; i++){MBHoldingRegister[Start + i] = word(ByteArray[ 13 + i * 2],ByteArray[14 + i * 2]);}MessageLength = 12;client.write((const uint8_t *)ByteArray,MessageLength);byteFN = MB_FC_NONE;break;}}}//===== getDistance - Custom Functionint getDistance() {// Clears the trigPindigitalWrite(trigPin, LOW);delayMicroseconds(2);// Sets the trigPin on HIGH state for 10 micro secondsdigitalWrite(trigPin, HIGH);delayMicroseconds(10);digitalWrite(trigPin, LOW);// Reads the echoPin, returns the sound wave travel time in microsecondsduration = pulseIn(echoPin, HIGH);// Calculating the distancedistance = duration * 0.034 / 2; // distance in cmreturn distance;}

Question by methaq_ali 


Ethernet.h causing problems with 7 segment display driver [Arduino]

Hey Instructables,  I have a really annoying issue with some Arduino code I am writing.  The code is for an ethernet controlled countdown timer.  In it's component parts the functions all work fine,  I can drive the 7 segment display fine. I can start/stop/set a count over Ethernet However as soon as I add the line  Ethernet.begin(mac, ip); in void setup()  The 7 segment display starts to show errors, specifically the first of the four digits. Even If I don't include any additional Ethernet related code in the loop, just calling the library on setup causes problems.  I'm not an especially experienced programmer so I'm really hoping someone can share a little of their wisdom here! #include #include          // needed for Arduino versions later than 0018 #include #include          // UDP library from: bjoern@cs.stanford.edu 12/30/2008 int digit1 = 11; //PWM Display pin 1 int digit2 = 10; //PWM Display pin 2 int digit3 = 9; //PWM Display pin 6 int digit4 = 6; //PWM Display pin 8 //Pin mapping from Arduino to the ATmega DIP28 if you need it //http://www.arduino.cc/en/Hacking/PinMapping int segA = A1; //Display pin 14 int segB = 3; //Display pin 16 int segC = 4; //Display pin 13 int segD = 5; //Display pin 3 int segE = A0; //Display pin 5 int segF = 7; //Display pin 11 int segG = 8; //Display pin 15 // Enter a MAC address and IP address for your controller below. // The IP address will be dependent on your local network: byte mac[] = {   0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; IPAddress ip(192, 168, 1, 177); unsigned int localPort = 8888;      // local port to listen on // buffers for receiving and sending data char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet, char ReplyBuffer[] = "acknowledged";       // a string to send back // An EthernetUDP instance to let us send and receive packets over UDP EthernetUDP Udp; elapsedMillis timeElapsed; //declare global if you don't want it reset every time loop runs //  milliseconds in a second unsigned int interval = 1000; unsigned int seconds = 0; unsigned int state = 1; unsigned int timeSetting = 10; unsigned int oldSeconds = 0; char theCount[9] = "01:06:30"; int secs = 0; int mins = 0; int hours = 0; String isItTime = ""; String firstFour = ""; void setup() {                      Ethernet.begin(mac, ip);   Udp.begin(localPort);      pinMode(segA, OUTPUT);   pinMode(segB, OUTPUT);   pinMode(segC, OUTPUT);   pinMode(segD, OUTPUT);   pinMode(segE, OUTPUT);   pinMode(segF, OUTPUT);   pinMode(segG, OUTPUT);   pinMode(digit1, OUTPUT);   pinMode(digit2, OUTPUT);   pinMode(digit3, OUTPUT);   pinMode(digit4, OUTPUT);     pinMode(13, OUTPUT);     } void loop() {     displayNumber(millis()/1000);    } void displayNumber(int toDisplay) { #define DISPLAY_BRIGHTNESS  500 #define DIGIT_ON  HIGH #define DIGIT_OFF  LOW   long beginTime = millis();   for(int digit = 4 ; digit > 0 ; digit--) {     //Turn on a digit for a short amount of time     switch(digit) {     case 1:       digitalWrite(digit1, DIGIT_ON);       break;     case 2:       digitalWrite(digit2, DIGIT_ON);       break;     case 3:       digitalWrite(digit3, DIGIT_ON);       break;     case 4:       digitalWrite(digit4, DIGIT_ON);       break;     }     //Turn on the right segments for this digit     lightNumber(toDisplay % 10);     toDisplay /= 10;     delayMicroseconds(DISPLAY_BRIGHTNESS); //Display this digit for a fraction of a second (between 1us and 5000us, 500 is pretty good)     //Turn off all segments     lightNumber(10);     //Turn off all digits     digitalWrite(digit1, DIGIT_OFF);     digitalWrite(digit2, DIGIT_OFF);     digitalWrite(digit3, DIGIT_OFF);     digitalWrite(digit4, DIGIT_OFF);   }   while( (millis() - beginTime) < 10) ; //Wait for 20ms to pass before we paint the display again } //Given a number, turns on those segments //If number == 10, then turn off number void lightNumber(int numberToDisplay) { #define SEGMENT_ON  LOW #define SEGMENT_OFF HIGH   switch (numberToDisplay){   case 0:     digitalWrite(segA, SEGMENT_ON);     digitalWrite(segB, SEGMENT_ON);     digitalWrite(segC, SEGMENT_ON);     digitalWrite(segD, SEGMENT_ON);     digitalWrite(segE, SEGMENT_ON);     digitalWrite(segF, SEGMENT_ON);     digitalWrite(segG, SEGMENT_OFF);     break;   case 1:     digitalWrite(segA, SEGMENT_OFF);     digitalWrite(segB, SEGMENT_ON);     digitalWrite(segC, SEGMENT_ON);     digitalWrite(segD, SEGMENT_OFF);     digitalWrite(segE, SEGMENT_OFF);     digitalWrite(segF, SEGMENT_OFF);     digitalWrite(segG, SEGMENT_OFF);     break;   case 2:     digitalWrite(segA, SEGMENT_ON);     digitalWrite(segB, SEGMENT_ON);     digitalWrite(segC, SEGMENT_OFF);     digitalWrite(segD, SEGMENT_ON);     digitalWrite(segE, SEGMENT_ON);     digitalWrite(segF, SEGMENT_OFF);     digitalWrite(segG, SEGMENT_ON);     break;   case 3:     digitalWrite(segA, SEGMENT_ON);     digitalWrite(segB, SEGMENT_ON);     digitalWrite(segC, SEGMENT_ON);     digitalWrite(segD, SEGMENT_ON);     digitalWrite(segE, SEGMENT_OFF);     digitalWrite(segF, SEGMENT_OFF);     digitalWrite(segG, SEGMENT_ON);     break;   case 4:     digitalWrite(segA, SEGMENT_OFF);     digitalWrite(segB, SEGMENT_ON);     digitalWrite(segC, SEGMENT_ON);     digitalWrite(segD, SEGMENT_OFF);     digitalWrite(segE, SEGMENT_OFF);     digitalWrite(segF, SEGMENT_ON);     digitalWrite(segG, SEGMENT_ON);     break;   case 5:     digitalWrite(segA, SEGMENT_ON);     digitalWrite(segB, SEGMENT_OFF);     digitalWrite(segC, SEGMENT_ON);     digitalWrite(segD, SEGMENT_ON);     digitalWrite(segE, SEGMENT_OFF);     digitalWrite(segF, SEGMENT_ON);     digitalWrite(segG, SEGMENT_ON);     break;   case 6:     digitalWrite(segA, SEGMENT_ON);     digitalWrite(segB, SEGMENT_OFF);     digitalWrite(segC, SEGMENT_ON);     digitalWrite(segD, SEGMENT_ON);     digitalWrite(segE, SEGMENT_ON);     digitalWrite(segF, SEGMENT_ON);     digitalWrite(segG, SEGMENT_ON);     break;   case 7:     digitalWrite(segA, SEGMENT_ON);     digitalWrite(segB, SEGMENT_ON);     digitalWrite(segC, SEGMENT_ON);     digitalWrite(segD, SEGMENT_OFF);     digitalWrite(segE, SEGMENT_OFF);     digitalWrite(segF, SEGMENT_OFF);     digitalWrite(segG, SEGMENT_OFF);     break;   case 8:     digitalWrite(segA, SEGMENT_ON);     digitalWrite(segB, SEGMENT_ON);     digitalWrite(segC, SEGMENT_ON);     digitalWrite(segD, SEGMENT_ON);     digitalWrite(segE, SEGMENT_ON);     digitalWrite(segF, SEGMENT_ON);     digitalWrite(segG, SEGMENT_ON);     break;   case 9:     digitalWrite(segA, SEGMENT_ON);     digitalWrite(segB, SEGMENT_ON);     digitalWrite(segC, SEGMENT_ON);     digitalWrite(segD, SEGMENT_ON);     digitalWrite(segE, SEGMENT_OFF);     digitalWrite(segF, SEGMENT_ON);     digitalWrite(segG, SEGMENT_ON);     break;   case 10:     digitalWrite(segA, SEGMENT_OFF);     digitalWrite(segB, SEGMENT_OFF);     digitalWrite(segC, SEGMENT_OFF);     digitalWrite(segD, SEGMENT_OFF);     digitalWrite(segE, SEGMENT_OFF);     digitalWrite(segF, SEGMENT_OFF);     digitalWrite(segG, SEGMENT_OFF);     break;   } }

Topic by drkovorkian   |  last reply


How to get data from a load sensor through bluetooth module on an Android App/Arduino?

I am creating a mobile android application which gets data from a load sensor connected to HC-06 Bluetooth module and sends the data to a mobile application. The mobile app has two activities one for listing the bluetooth devices available and the other is the main activity to get data from the load sensor. I have managed to connect/pair with the Bluetooth module but I am unable to get data from it. The main activity consists of a button 'btnScan' that will get the data, and a text field to display the data. Can someone please help?  Here is the MainActivity File package com.uniproj.senseplate; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.UUID; import android.app.Activity; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothSocket; import android.content.Intent; import android.os.Bundle; import android.os.Handler; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.TextView; import android.widget.Toast;   public class MainActivity extends Activity {       Button btnscan;   TextView txtArduino, txtString, txtStringLength, calorie;   Handler bluetoothIn;   final int handlerState = 0;             //used to identify handler message   private BluetoothAdapter btAdapter = null;   private BluetoothSocket btSocket; //= null;   private StringBuilder recDataString = new StringBuilder();      private ConnectedThread mConnectedThread;       // SPP UUID service - this should work for most devices   private static final UUID BTMODULEUUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");     // String for MAC address   private static String address; @Override   public void onCreate(Bundle savedInstanceState) {     super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);       //Link the buttons and textViews to respective views                    btnscan = (Button) findViewById(R.id.scanBtn);                 txtString = (TextView) findViewById(R.id.txtString);     txtStringLength = (TextView) findViewById(R.id.testView1);       calorie = (TextView) findViewById(R.id.sensorView1);     bluetoothIn = new Handler() {         public void handleMessage(android.os.Message msg) {             if (msg.what == handlerState) {          //if message is what we want              String readMessage = (String) msg.obj;                                                                // msg.arg1 = bytes from connect thread                 recDataString.append(readMessage);              //keep appending to string until ~                 int endOfLineIndex = recDataString.indexOf("~");                    // determine the end-of-line                 if (endOfLineIndex > 0) {                                           // make sure there data before ~                     String dataInPrint = recDataString.substring(0, endOfLineIndex);    // extract string                     txtString.setText("Data Received = " + dataInPrint);                                 int dataLength = dataInPrint.length();       //get length of data received                     txtStringLength.setText("String Length = " + String.valueOf(dataLength));                                         if (recDataString.charAt(0) == '#')        //if it starts with # we know it is what we are looking for                     {                      //get sensor value from string between indices 1-5                      String weight = recDataString.substring(1, 5);                      //update the textviews with sensor values                      calorie.setText(weight + "kg");                            }                     recDataString.delete(0, recDataString.length());      //clear all string data                    // strIncom =" ";                     dataInPrint = " ";                 }                        }         }     };           btAdapter = BluetoothAdapter.getDefaultAdapter();       // get Bluetooth adapter     checkBTState();        // Set up onClick listeners for button to scan for data     btnscan.setOnClickListener(new OnClickListener() {       public void onClick(View v) {         mConnectedThread.read("1");       }     }); }   private BluetoothSocket createBluetoothSocket(BluetoothDevice device) throws IOException {             return  device.createRfcommSocketToServiceRecord(BTMODULEUUID);       //creates secure outgoing connecetion with BT device using UUID   }       @Override   public void onResume() {     super.onResume();         //Get MAC address from DeviceListActivity via intent     Intent intent = getIntent();         //Get the MAC address from the DeviceListActivty via EXTRA     address = intent.getStringExtra(DeviceListActivity.EXTRA_DEVICE_ADDRESS);     //create device and set the MAC address     BluetoothDevice device = btAdapter.getRemoteDevice(address);          try {         btSocket = createBluetoothSocket(device);     } catch (IOException e) {      Toast.makeText(getBaseContext(), "Socket creation failed", Toast.LENGTH_LONG).show();     }      // Establish the Bluetooth socket connection.     try     {       btSocket.connect();     } catch (IOException e) {       try       {         btSocket.close();       } catch (IOException e2)       {      //insert code to deal with this       }     }     mConnectedThread = new ConnectedThread(btSocket);     mConnectedThread.start();         //I send a character when resuming.beginning transmission to check device is connected     //If it is not an exception will be thrown in the write method and finish() will be called     //mConnectedThread.write("x");   }     @Override   public void onPause()   {     super.onPause();     try     {     //Don't leave Bluetooth sockets open when leaving activity       btSocket.close();     } catch (IOException e2) {      //insert code to deal with this     }   } //Checks that the Android device Bluetooth is available and prompts to be turned on if off   private void checkBTState() {     if(btAdapter==null) {      Toast.makeText(getBaseContext(), "Device does not support bluetooth", Toast.LENGTH_LONG).show();     } else {       if (btAdapter.isEnabled()) {       } else {         Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);         startActivityForResult(enableBtIntent, 1);       }     }   }     //create new class for connect thread   private class ConnectedThread extends Thread {         private final InputStream mmInStream;         @SuppressWarnings("unused")   private final OutputStream mmOutStream;               //creation of the connect thread         public ConnectedThread(BluetoothSocket socket) {          btSocket = socket;             InputStream tmpIn = null;             OutputStream tmpOut = null;             try {              //Create I/O streams for connection                 tmpIn = socket.getInputStream();                 tmpOut = socket.getOutputStream();             } catch (IOException e) { }                   mmInStream = tmpIn;             mmOutStream = tmpOut;         }                 public void run() {             byte[] buffer = new byte[1024];              int bytes;             // Keep looping to listen for received messages             while (true) {                 try {                     bytes = mmInStream.read(buffer);                     bluetoothIn.obtainMessage(handlerState, bytes, -1, buffer).sendToTarget();                 } catch (IOException e) {                     break;                 }             }         }                 //write method         public void read(String input) {             byte[] bytes = input.getBytes();//converts entered String into bytes             try {                 mmInStream.read(bytes);//write bytes over BT connection via outstream             } catch (IOException e) {               //if you cannot write, close the application              Toast.makeText(getBaseContext(), "Connection Failed", Toast.LENGTH_LONG).show();              finish();                            }          }      } } Here is the Arduino file #include int led = 13; int button = 12; LiquidCrystal lcd(9, 8, 4, 5, 6, 7); // Pins used for inputs and outputs******************************************************** float sensorValue1; float containerValue; char inbyte = 0; int flag; const int numReadings = 50; int readings[numReadings]; int index = 0; int total = 0; int average = 0; //******************************************************************************************* void setup() {     pinMode(led, OUTPUT);   digitalWrite(led, HIGH);   Serial.begin(9600);     for (int thisReading = 0; thisReading < numReadings; thisReading++)   {       readings[thisReading] = 0;   }     lcd.begin(16, 2); //change to 16, 2 for smaller 16x2 screens   lcd.clear();   lcd.print("hello, world!");   delay (1000);   lcd.clear();   delay (500); } void loop() {   digitalWrite(led, HIGH);   readSensor2();    //DONE       printLCD();       //DONE   return; sendAndroidValues();   //when serial values have been received this will be true   if (Serial.available() > 0)   {     inbyte = Serial.read();     if (inbyte == '0')     {       //LED off       digitalWrite(led, LOW);     }     if (inbyte == '1')     {       //LED on       digitalWrite(led, HIGH);     }   }     //delay by 2s. Meaning we will be sent values every 2s approx   //also means that it can take up to 2 seconds to change LED state   delay(2000); void readSensor2() {   total = total - readings[index];     readings[index] = analogRead(A0);     total = total + readings[index];     index = index + 1;     if (index >= numReadings)   {      index = 0;   }     average = total / numReadings;        //sensorValue1 = (analogRead(A0) - 330)* i;    //delay(200);         Serial.println(average);    delay(100);          if( digitalRead(button) == HIGH && flag == 1)   {     flag = 0;     containerValue = 0;      }   else if (digitalRead(button) == HIGH && flag != 1) {   flag = 1;                        //when the button is pressed the initially sesnsor     containerValue = sensorValue1;      delay(10);   }     //Serial.println(digitalRead(button));    delay (1000);    } //sends the values from the sensor over serial to BT module void sendAndroidValues() {   //puts # before the values so our app knows what to do with the data Serial.print('#');   //for loop cycles through 4 sensors and sends values via serial   Serial.print(sensorValue1);   Serial.print('+');     //technically not needed but I prefer to break up data values     //so they are easier to see when debugging Serial.print('~'); //used as an end of transmission character - used in app for string length Serial.println(); delay(5000);        //added a delay to eliminate missed transmissions } void printLCD() {   lcd.setCursor(4, 0);   lcd.print("   GRAMS    ");   lcd.setCursor(4, 1);   lcd.print(sensorValue1); }

Question by AyoS1   |  last reply


Change a 7 seg display from CC to CA in code? Answered

I am not as familiar with C/C++ as i am with Arduino. I am wanting to change this code from Common Cathode to Common Anode. How can i do this? //_____________________ fuse.c #define F_CPU 8000000UL #include #include #include #include #include #define _REVERSE #define _OPT_BUTTON_ /* . document tab-stop set to 4, best viewed w/ vi set to ":set ts=4" . description   this project is created so that if i could revert the RESET fuse change and flash via   SPI again. . features   . reads device signature and hi-low fuses for hi-voltage serial programmable attinys   . reset hi-low fuses to factory default on target devices   . layout to drop-on attiny13, attiny25/45/85 8 pin devices targets   . attiny24/44/84 targets needs additional breadboard and jumper wires   . standalone operations, fuses show on 7 segment display . project fuse setting   avrdude -c usbtiny -p t2313 -V -U lfuse:w:0xe4:m -U hfuse:w:0xdf:m -U efuse:w:0xff:m . parts list   . attiny2313   . 4x7 segment LED display   . 1k resistor x 2   . 2n2222 NPN transistor or equivalent   . 78L05   . mini breadboard 170 tiepoints   . +12V battery source . opearation   . place 8 pin target device on breadboard   . for 14 pin targets, jumper wire to breadboard   . apply 12V power   . display shows device name upon identification   . press and release button to cycle display content   . displays device name, fuse hi bits, fuse low bits and fuse extended bits   . long press and release button to reset fuse to factory default   . references and related projects   . datasheets   . avrdoper http://www.obdev.at/avrusb/avrdoper.html/   . mightyohm http://www.mightyohm.com/blog/2008/09/arduino-based-avr-high-voltage-programmer/                  Gd 12V                  Gd Rt V+ Ck MI MO (tinyusb programmer)                   +  +  +  +  +  +    +=====================================================+    |  .  .  .  .  .  I  .  .  .  .  .  .  .  .  .  .  .  | [I]n (78L05)    |  .  .  .  .  C  .  .  .  .  .  .  .  .  .  .  .  .  | [C]ommon    |  .  .  .  .  .  .  O  .  .  .  .  .  .  .  .  .  .  | [O]ut    | (v)(d)(b)(c) +--------o (v) .  .  .  .  . (d)(c) .  |    |  +--+--+--+  |  o  +--+-(1)-A--F-(2)(3)-B--+--+  .  |    | |+         | 1k | |+ b7..6..5..4..3..2..1..0 d6|    |    | |         -| |  1k|R d0..1 a1..0 d2..3..4..5  -|    |    |  +--+--+--+  o  |  +--+--+--+--+--+--+--+--+--+  .  |    |  .  .  .  .  .  o  -  -  E  D (.) C  G (4) -  -  .  |    |  o--------------o  .  .  .  .  .  .  .  .  .  .  .  |    |  . (a) .  E  B  C  . (a) .  .  .  .  .  . (b) .  .  | EBC of 2n2222    |  .  .  .  .  .  .  .  .  .  .  .  .  .  o--B--o  .  |    +=====================================================+                     (p)(p)                                 join (p)(p) during programming       SDO   SDI     +--+--+--+    |+    SII  |    |R        -|     +--+--+--+       SCI #define HIV _BV(7) //b7 .. RESET #define VCC _BV(6) //b6 .. (v) #define SDO _BV(0) //b0 .. (d) #define SCI _BV(0) //d0 .. (a) #define SII _BV(5) //d5 .. (b) #define SDI _BV(6) //d6 .. (c) */ #define BUTTON_DDR   DDRD #define BUTTON_PORT  PORTD #define BUTTON_PIN   _BV(4) #define SEG_A_PB _BV(5) #define SEG_B_PB _BV(1) #define SEG_C_PB 0x00 #define SEG_D_PB 0x00 #define SEG_E_PB 0x00 #define SEG_F_PB _BV(4) #define SEG_G_PB 0x00 #define SEG_d_PB 0x00 #define DIGIT_0_PB _BV(6) #define DIGIT_1_PB _BV(3) #define DIGIT_2_PB _BV(2) #define DIGIT_3_PB 0x00 #define SEG_A_PD 0x00 #define SEG_B_PD 0x00 #define SEG_C_PD _BV(2) #define SEG_D_PD _BV(7)  // d.7 maps to a.1 #define SEG_E_PD _BV(1) #define SEG_F_PD 0x00 #define SEG_G_PD _BV(3) //#define SEG_d_PD 0x00 #define SEG_d_PD _BV(6)  // d.6 maps to a.0 #define DIGIT_0_PD 0x00 #define DIGIT_1_PD 0x00 #define DIGIT_2_PD 0x00 #define DIGIT_3_PD _BV(4) #ifdef _REVERSE #define HOLD_DDR_VAL 0x60 #define HOLD_VAL   0x40 #else #define HOLD_DDR_VAL 0x18 #define HOLD_VAL   0x08 #endif #define SEGS_STAY(v) \    (((v & _BV(6)) ? 1 : 0) +\ ((v & _BV(5)) ? 1 : 0) +\ ((v & _BV(4)) ? 1 : 0) +\ ((v & _BV(3)) ? 1 : 0) +\ ((v & _BV(2)) ? 1 : 0) +\ ((v & _BV(1)) ? 1 : 0) +\ ((v & _BV(0)) ? 1 : 0)) | 0x40 #define SEGS_PORT_DET(p, v) \    (((v & _BV(6)) ? SEG_A_P##p : 0) | \ ((v & _BV(5)) ? SEG_B_P##p : 0) | \ ((v & _BV(4)) ? SEG_C_P##p : 0) | \ ((v & _BV(3)) ? SEG_D_P##p : 0) | \ ((v & _BV(2)) ? SEG_E_P##p : 0) | \ ((v & _BV(1)) ? SEG_F_P##p : 0) | \ ((v & _BV(0)) ? SEG_G_P##p : 0)) #define SEGS_PORT(v) {SEGS_STAY(v),SEGS_PORT_DET(B, v),SEGS_PORT_DET(D, v)} #define SEGS_B (SEG_A_PB|SEG_B_PB|SEG_C_PB|SEG_D_PB|SEG_E_PB|SEG_F_PB|SEG_G_PB|SEG_d_PB) #define SEGS_D (SEG_A_PD|SEG_B_PD|SEG_C_PD|SEG_D_PD|SEG_E_PD|SEG_F_PD|SEG_G_PD|SEG_d_PD) #define DIGITS_B (DIGIT_0_PB|DIGIT_1_PB|DIGIT_2_PB|DIGIT_3_PB) #define DIGITS_D (DIGIT_0_PD|DIGIT_1_PD|DIGIT_2_PD|DIGIT_3_PD) #define USED_B (SEGS_B|DIGITS_B) #define USED_D (SEGS_D|DIGITS_D) /*        ___a__       |      |      f|      | b        ___g__      e|      | c       |      |        ___d__ */ //_____________________ abc defg #define LTR_0 0x7e // 0111 1110 #define LTR_1 0x30 // 0011 0000 #define LTR_2 0x6d // 0110 1101 #define LTR_3 0x79 // 0111 1001 #define LTR_4 0x33 // 0011 0011 #define LTR_5 0x5b // 0101 1011 #define LTR_6 0x5f // 0101 1111 #define LTR_7 0x70 // 0111 0000 #define LTR_8 0x7f // 0111 1111 #define LTR_9 0x7b // 0111 1011 #define LTR_A 0x77 // 0111 0111 #define LTR_b 0x1f // 0001 1111 #define LTR_C 0x4e // 0100 1110 #define LTR_d 0x3d // 0011 1101 #define LTR_E 0x4f // 0100 1111 #define LTR_F 0x47 // 0100 0111 #define LTR_P 0x67 // 0110 0111 #define LTR_G 0x5e // 0101 1110 #define LTR_n 0x15 // 0001 0101 #define LTR_r 0x05 // 0000 0101 #define LTR_t 0x0f // 0000 1111 #define LTR__ 0x00 // 0000 0000 uint8_t EEMEM digit2ports[][3] = { SEGS_PORT(LTR_0), SEGS_PORT(LTR_1), SEGS_PORT(LTR_2), SEGS_PORT(LTR_3), SEGS_PORT(LTR_4), SEGS_PORT(LTR_5), SEGS_PORT(LTR_6), SEGS_PORT(LTR_7), SEGS_PORT(LTR_8), SEGS_PORT(LTR_9), SEGS_PORT(LTR_A), SEGS_PORT(LTR_b), SEGS_PORT(LTR_C), SEGS_PORT(LTR_d), SEGS_PORT(LTR_E), SEGS_PORT(LTR_F), SEGS_PORT(LTR_r), SEGS_PORT(LTR_P), SEGS_PORT(LTR_G), SEGS_PORT(LTR_n), SEGS_PORT(LTR_t), SEGS_PORT(LTR__), }; enum { POS_0, POS_1, POS_2, POS_3, POS_4, POS_5, POS_6, POS_7, POS_8, POS_9, POS_A, POS_b, POS_C, POS_d, POS_E, POS_F, POS_r, POS_P, POS_G, POS_n, POS_t, POS__, }; #define ST_HOLD  0x80 #define ST_PRESSED 0x40 #define ST_BUTTON   (ST_HOLD|ST_PRESSED) #define ST_TICKED 0x20 #define ST_12HR  0x10 #define ST_REFRESH 0x08 #define ST_BUZZ     0x04 #define ST_SETUP    0x03 #define ST_SENSE ST_BUZZ volatile uint8_t busy=0; volatile uint8_t state=ST_REFRESH|ST_12HR; volatile uint8_t dim=1; uint8_t  pos=0, stays; uint8_t  mode=0; #ifdef _OPT_SENSE_ uint16_t charged=0; #endif uint16_t button=0; uint16_t clicks=0, ticks=0; //_______________________ ticks per second and devired values #define TPS   (F_CPU/256) #define TPS_2 (TPS/2) #define TPS_4 (TPS/4) #define LONG_HOLD (TPS/3) #define NUM_DIGITS 4 static const uint8_t digit_mapb[] PROGMEM = { 0x40,0x08,0x04,0x00 }; static const uint8_t digit_mapd[] PROGMEM = { 0x00,0x00,0x00,0x10 }; //_________________ list of porta..c,ddra..c,stay * number_of_digits uint8_t output[3 * NUM_DIGITS]; uint8_t *ioptr = output; uint8_t dot = 0x00; //__________________________________________________ ISR(TIMER0_OVF_vect) { clicks++; if (clicks >= TPS) {   clicks = 0;   state |= ST_TICKED;   ticks++; }//if if (stays & 0x0f) { stays--; return; } stays >>= dim; DDRA  &= ~(USED_D>>6); DDRB  &= ~USED_B; DDRD  &= ~(USED_D&0x3f); PORTA &= ~(USED_D>>6); PORTB &= ~USED_B; PORTD &= ~(USED_D&0x3f); if (stays) { stays--; return; } if (busy) return; #ifdef _OPT_BUTTON_ //___________ scan button PORTD |= BUTTON_PIN; _delay_us(1);  // allow pull-up to settle if (PIND & BUTTON_PIN) {   if (button) {    if (button > 30) {     //_________ released     if (button > LONG_HOLD)      state |= ST_HOLD;     else      state |= ST_PRESSED;     stays = 0x14;    }//if   }//if   else {    stays = 0x10;   }//else   button = 0; }//if else {   //_____________ pressed   button++;   if (button > LONG_HOLD) { // show long hold #ifdef _REVERSE    DDRB |= HOLD_DDR_VAL; PORTB |= HOLD_VAL; #else    DDRD |= HOLD_DDR_VAL; PORTD |= HOLD_VAL; #endif   }//if }//else PORTD &= ~BUTTON_PIN; DDRD  &= ~(USED_D&0x3f); PORTD &= ~(USED_D&0x3f); if (state & ST_BUTTON) return; if (button) return; #endif #ifdef _OPT_SENSE_ if (!charged && (state & ST_SENSE)) {   state &= ~ST_SENSE;   DDRB  = 0x00; PORTB = 0x00;   DDRD  = 0x00; PORTD = 0x00;   _delay_us(1);   //_________ charge sensor led   charged = 1;   //SENSE_CHARGE   DDRA  |=  SEGS_D>>6;   PORTA &= ~(SEGS_D>>6);   DDRB  |=  SEGS_B;   PORTB &= ~SEGS_B;   DDRD  |=  SEGS_D&0x3f;   PORTD &= ~(SEGS_D&0X3f);   DDRB  &= ~0x44;   PORTB |=  0x44;   //DDRB  &= ~_BV(6);   //PORTB |= _BV(6);   //_delay_us(1);   //asm volatile("nop\n\tnop\n\tnop\n\tnop\n\t"::);   //asm volatile("nop\n\tnop\n\tnop\n\tnop\n\t"::);   //asm volatile("nop\n\tnop\n\tnop\n\tnop\n\tnop\n\t"::);   //while (!SENSE_BUTT);   //PORTB &= ~_BV(6);   while (!SENSE_ALL);   PORTB &= ~0x44;   return; }//if #endif //___________ load segments uint8_t portd = *ioptr++; uint8_t portb = *ioptr++; uint8_t porta = portd >> 6; portd &= 0x3f; //uint8_t mapb = digit_mapb[pos]; //uint8_t mapd = digit_mapd[pos]; uint8_t mapb = pgm_read_byte(&digit;_mapb[pos]); uint8_t mapd = pgm_read_byte(&digit;_mapd[pos]); DDRA  |= porta; DDRB  |= portb | mapb; DDRD  |= portd | mapd; #ifdef _REVERSE PORTA |= ~porta; PORTB |= ~portb & mapb; PORTD |= ~portd & mapd; #else PORTA |= porta; PORTB |= portb & ~mapb; PORTD |= portd & ~mapd; #endif stays  = *ioptr++; if (stays && (state & ST_SETUP) && (clicks / TPS_2) &&   ((pos == (state & ST_SETUP)) ||   (!pos && !(state & 0x02))))   stays = 0x08; pos++; if (pos >= 4) {   pos = 0;   ioptr = output; }//if } //__________________________________________________ void seg2port(uint8_t bcd, uint8_t which) { if (which & 0x40) {   //_____________ bcd entry, do 2nd digit 1st, then 1st digit   which &= 0x0f;   seg2port(bcd&0x0f, which+1);   bcd >>= 4; }//if uint8_t *pp = output + which * 3; uint8_t offset = 3; busy++; do {   *pp++ = eeprom_read_byte(&digit2ports;[bcd][--offset]); } while (offset); busy--; } #define HIV _BV(7) //b7 #define VCC _BV(6) //b6 #define SDO _BV(0) //b0 #define SCI _BV(0) //d0 #define SII _BV(5) //d5 #define SDI _BV(6) //d6 #define SCI_PULSE _delay_us(1); PORTD |= SCI; _delay_us(1); PORTD &= ~SCI; //__________________________________________________ uint8_t hv_cmd(uint8_t *dptr, uint8_t cnt) { // data format is like write 0_DDDD_DDDD_00 //                      read D_DDDD_DDDx_xx uint8_t sdo=0x00; while (cnt) {   uint8_t sdi = *dptr++;   uint8_t sii = *dptr++;   uint8_t cmp=0x80;   sdo = 0x00;   PORTD &= ~(SDI|SII);   SCI_PULSE;   //sdo = ((PINB&SDO;) ? 1 : 0);   //sdo = ((PINB&SDO;) ? 0 : 1);   // 0x1e92 06   // 0x62df b0110 0010 1101 1111   while (cmp) {    sdo <<= 1;    //sdo |= ((PINB&SDO;) ? 0 : 1);    //sdo |= ((PINB&SDO;) ? 1 : 0);    if (PINB&SDO;) sdo |= 0x01;    PORTD &= ~(SDI|SII);    if (cmp&sdi;) PORTD |= SDI;    //else         PORTD &= ~SDI;    if (cmp&sii;) PORTD |= SII;    //else         PORTD &= ~SII;    SCI_PULSE;    //sdo |= (PINB&SDO;) ? 1 : 0;    cmp >>= 1;   }//while   PORTD &= ~(SDI|SII);   SCI_PULSE;   SCI_PULSE;   _delay_us(100);   cnt--; }//while //sdo = cnt; return sdo; } uint8_t chip_sig[] = { 0xee, 0xee, 0xee, 0xee, 0x00, 0x00 }; //__________________________________________________ void read_chip(uint8_t release_reset) { cli(); busy++; // enter hv mode, everything go low DDRB  |= (VCC|HIV|SDO); PORTB &= ~(VCC|SDO);// Vcc and data out off PORTB |= HIV;  // 12v off DDRD  |= (SCI|SDI|SII); PORTD &= ~(SCI|SDI|SII); //_delay_ms(50); PORTB |= VCC;  // Vcc on _delay_us(40); PORTB &= ~HIV;  // turn on 12v _delay_us(15); DDRB  &= ~SDO;  // release SDO _delay_us(300); // should be ready to issue commands // read signature // // default fuse settting taken from http://www.engbedded.com/fusecalc/ // // mcu - id          - factory fuse low-high-extended // t13 - 1e9007 (07) - 6a-ff // t25 - 1e9108 (18) - 62-df-ff // t45 - 1e9206 (26) - 62-df-ff // t85 - 1e930b (3b) - 62-df-ff // t24 - 1e910b (1b) - 62-df-ff // t44 - 1e9207 (27) - 6a-df-ff // t84 - 1e930c (3c) - 6a-df-ff // signature  { 0x08, 0x4c, 0xpp, 0x0c,      0x00, 0x68,      0x00, 0x6c // write fuse { 0x40, 0x4c, val,  0x2c,      0x00, 0x64/0x74, 0x00, 0x6c/0x7c // read fuse  { 0x04, 0x4c, 0x00, 0x68/0x7a, 0x00, 0x6c/0x7c uint8_t cmd[] = { 0x08, 0x4c, 0x00, 0x0c, 0x00, 0x68, 0x00, 0x6c, }; uint8_t *pdata = chip_sig; uint8_t i; //____________________ read device signature for (i=0;i<3;i++) {   cmd[2] = i;   if (i)    *pdata++ = hv_cmd(&cmd;[2], 3);   else    *pdata++ = hv_cmd(cmd, 4); }//for uint8_t  id[] = { 0x07, 0x18, 0x26, 0x3b, 0x1b, 0x27, 0x3c, }; uint8_t mcu[] = { 0x13, 0x25, 0x45, 0x85, 0x24, 0x44, 0x84, }; if ((chip_sig[0] == 0x1e) && ((chip_sig[1]&0xf0) == 0x90) &&   !(chip_sig[2]&0xf0)) {   chip_sig[1] <<= 4;   chip_sig[1] |= chip_sig[2];   /*   switch (chip_sig[1]) {    case 0x07: chip_sig[1] = 0x13; break;    case 0x18: chip_sig[1] = 0x25; break;    case 0x26: chip_sig[1] = 0x45; break;    case 0x3b: chip_sig[1] = 0x85; break;    case 0x1b: chip_sig[1] = 0x24; break;    case 0x27: chip_sig[1] = 0x44; break;    case 0x3c: chip_sig[1] = 0x84; break;    default: chip_sig[1] = 0xee; break;   }//switch   chip_sig[0] = 0x00;   */   for (i=0;i<7;i++) {    if (chip_sig[1] == id[i]) {     chip_sig[0] = i;     chip_sig[1] = mcu[i];    }//if   }//for   pdata--; }//if //____________________ reset fuse if (release_reset) {   cmd[0] = 0x40;   //________________ write fuse low bits   cmd[3] = 0x2c; cmd[5] = 0x64;   if (chip_sig[1] == 0x13 || chip_sig[1] == 0x44 || chip_sig[1] == 0x84)    cmd[2] = 0x6a;   else    cmd[2] = 0x62;   hv_cmd(cmd, 4); _delay_ms(50);   //________________ write fuse high bits   cmd[5] = 0x74; cmd[7] = 0x7c;   if (chip_sig[1] == 0x13)    cmd[2] = 0xff;   else    cmd[2] = 0xdf;   hv_cmd(cmd, 4); _delay_ms(50);   //________________ write fuse extended bits   if (chip_sig[1] != 0x13) {    cmd[5] = 0x66; cmd[7] = 0x6e;    cmd[2] = 0x01;    hv_cmd(cmd, 4); _delay_ms(50);   }//if }//if //____________________ read fuse cmd[0] = 0x04; cmd[2] = 0x00; cmd[3] = 0x68; cmd[5] = 0x6c;   // fuse low *pdata++ = hv_cmd(cmd, 3); cmd[3] = 0x7a; cmd[5] = 0x7c;   // fuse high *pdata++ = hv_cmd(cmd, 3); if (chip_sig[1] != 0x13) {   cmd[3] = 0x6a; cmd[5] = 0x6e;  // fuse extended   *pdata++ = hv_cmd(cmd, 3); }//if // done, turn things off PORTB |= HIV; PORTB &= ~(VCC|SDO); PORTD &= ~(SCI|SDI|SII); busy--; sei(); } uint8_t menu=0, loc=0; //__________________________________________________ void main(void) { TCCR0B |= 0x01; TIMSK  |= _BV(TOIE0); TCNT0   = 0x00; DDRA = PORTA = 0; DDRD = PORTD = 0; DDRB   = (VCC|HIV|SDO); //DDRB   = (VCC|SDO); PORTB  = HIV;  // 12v off _delay_ms(50); read_chip(0); sei(); while (1) {   //_____________ "state" bits LBTSRZPP   //              L - long hold, B - button, T - ticked, S - setup mode,   //              R - refresh,   Z - buzzer  PP - digit edit position   //   //_____________ "menu" bits TxxOxMMM   //              T   - in toggle mode   //              O   - option used   //              MMM - menu id (1-4)   if (state & ST_TICKED) {    state &= ~ST_TICKED;   }//if   if (state & ST_REFRESH) {    state &= ~ST_REFRESH;    dot = _BV(mode);    if (mode) {     seg2port(chip_sig[mode*2], 0x40);    }//if    else {     seg2port(POS__, 0);     seg2port(POS_t, 1);    }//else    seg2port(chip_sig[mode*2+1], 0x42);   }//if   //_____________________________________ check input   if (state & ST_BUTTON) { // needs attention    loc = 0;    if (state & ST_PRESSED) {     // normal pressed, rotate display mode     mode++;     if (mode >= 3) mode = 0;    }//if    else {     // pressed and held, reset fuse     mode = 0;     read_chip(1);     _delay_us(100);     read_chip(0);    }//else    state &= ~ST_BUTTON;    state |= ST_REFRESH;   }//if }//while }

Question by WWC   |  last reply