element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum convert this arduino sketch to attiny85
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Not Answered
  • Replies 4 replies
  • Subscribers 392 subscribers
  • Views 541 views
  • Users 0 members are here
  • attiny85
  • arduino
Related

convert this arduino sketch to attiny85

gub11
gub11 over 10 years ago

I have this sketch

[code]

int analogValue;          // This is where we'll store our audio to digital value.  More sound = higher number
#define LED 2             // Set up the LED indicator
boolean toggle = false;   // setup a boolean function called toggle which will help us to choose which mode we're in
int numberOfClaps = 0;
void setup()
{
  pinMode(LED,OUTPUT);    // Pin#2 should be conencted to an LED through a 300-600 ohm resistor   
  Serial.begin(9600);     // This is optional - It just helps you to calibrate sensitivity after the fact
}

void loop()
{
  if (toggle == false)   // When you power up your arduino, boolean "toggle" is set to false, so the following section of code will                          //commence.  The "ELSE" is ignored for now.
    {
      digitalWrite
(LED,LOW);        // Turn the LED off
      analogValue = analogRead(0);  // Take an analog reading from A0 line.  No sounds should be offer a returned value of "0"
      if (analogValue > 8)          // If higher than 8 is returned, then change state of boolean "toggle" to true, display analogValue to                                     // serial monitor and wait 200ms.
      // The higher the value in the above "if" statement, the less sensitive your clapper will be.  Use the serial monitor to calibrate to       // your wanted sensitivity =D
      {
        toggle = true;
        Serial.println(analogValue);
        delay(200);
      }
    }
    else                            // If boolean "toggle" has beenchanged to true, then the above section of code will be ignored, and the                                     // code below will commence.
    {
      digitalWrite(LED,HIGH);       // Turn the LED on
      analogValue = analogRead(0);  // Take an analog reading from A0 line.  No sounds should be offer a returned value of "0"
      if (analogValue > 8)          // If higher than 8 is returned, then change state of boolean "toggle" back to false, print analogValue                                     // to serial monitor and wait 200ms.
      // The higher the value in the above "if" statement, the less sensitive your clapper will be.  Use the serial monitor to calibrate to       // your wanted sensitivity =D
      {
        toggle = false;
        Serial.println(analogValue);
        delay(200);
      }
    }
}

[/code]

I changed the pins obviously, pin 0 becomes pin 2(which is analog input on the attiny85) and the LED pin becomes pin 0(pwm pin on the attiny85(irealize i don't need pwm but there are no just digital out pins on the attiny)).  the circuit, when hooked up properly to an arduino uno works great, one clap will send a signal to a0 and turn on an led, another clap will turn it off, but on the tiny, its like it's disregarding my sketch completely because the led just goes on for 5 seconds, then off.

what's goin on here?

  • Sign in to reply
  • Cancel

Top Replies

  • balearicdynamics
    balearicdynamics over 10 years ago in reply to gadget.iom +1
    Yes Paul. Same person, same code Bah. I am tired to support in this way, honestly.
  • gadget.iom
    gadget.iom over 10 years ago in reply to balearicdynamics +1
    Yeah, thought as much. I don't see any point in porting this project to the ATtiny until the code is working on the UNO.
Parents
  • gub11
    0 gub11 over 10 years ago

    I got it working in the uno  image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • gub11
    0 gub11 over 10 years ago

    I got it working in the uno  image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube